Submission #402566

#TimeUsernameProblemLanguageResultExecution timeMemory
402566penguinhackerExercise Deadlines (CCO20_day1problem2)C++14
25 / 25
309 ms22748 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; const int mxN=2e5; int n, a[mxN]; vector<int> oc[mxN]; ll ans; set<int> s; tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> t; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i=0; i<n; ++i) { cin >> a[i], --a[i]; oc[a[i]].push_back(i); } for (int i=n-1; ~i; --i) { for (int j : oc[i]) s.insert(j); if (s.empty()) { cout << -1; return 0; } int x=*s.rbegin(); s.erase(--s.end()); t.insert(x); x-=t.order_of_key(x); ans+=i-x; } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...