diff --git a/src/week4/BOJ3015/BOJ3015_V1.cpp b/src/week4/BOJ3015/BOJ3015_V1.cpp new file mode 100644 index 0000000..641b340 --- /dev/null +++ b/src/week4/BOJ3015/BOJ3015_V1.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; +int n; +long long int ret, temp; +stack> s; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> n; + + for (int i = 0; i < n; i++) { + cin >> temp; + int cnt = 1; + while (s.size() && s.top().first <= temp) { + ret += s.top().second; + if (s.top().first == temp) { + cnt = s.top().second + 1; + } else { + cnt = 1; + } + s.pop(); + } + + if (s.size()) ret++; + s.push({temp,cnt}); + } + + cout << ret << '\n'; + return 0; +} \ No newline at end of file