# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
708011 | TAhmed33 | Baloni (COCI15_baloni) | C++98 | 273 ms | 11852 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int arr[n + 1] = {0};
unordered_map<int, deque<int>> pos;
int mx = 0;
int mn = 1e9;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
mx = max(mx, arr[i]);
mn = min(mn, arr[i]);
pos[arr[i]].push_back(i);
}
int ans = 0;
while (mx >= mn) {
if (pos[mx].size() == 0) {
mx--;
continue;
}
int arrow = mx;
int cur = pos[mx].front();
arrow--;
pos[mx].pop_front();
while (arrow != 0) {
if (pos[arrow].size() == 0) break;
int ub = upper_bound(pos[arrow].begin(), pos[arrow].end(), cur) - pos[arrow].begin();
if (ub == pos[arrow].size()) {
break;
}
cur = pos[arrow][ub];
pos[arrow].erase(pos[arrow].begin() + ub);
arrow--;
}
ans++;
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |