# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
307137 | 2020-09-27T07:30:06 Z | Tamarpeikrishvili | Exercise Deadlines (CCO20_day1problem2) | C++14 | 1000 ms | 5120 KB |
#include <bits/stdc++.h> using namespace std; int tree[200005]; long long ans = 0; vector <int> v[200005]; priority_queue <int> pq; int get(int idx){ int sum = 0; while (idx > 0){ sum += tree[idx]; idx = idx - (idx & -idx); } return sum; } void upd(int idx ,int val, int MaxVal){ while (idx <= MaxVal){ tree[idx] += val; idx += (idx & -idx); } } int main (){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a[n]; for(int i=1; i<=n; i++) { cin >> a[i]; v[a[i]].push_back(i); } sort(a+1, a+n+1); for(int i=1; i<=n; i++){ if(a[i] < i){ cout << -1 << endl; return 0; } } for(int i=1; i<=n; i++) upd(i , 1, n); for(int i=n; i>0; i--){ for(int j=0; j<v[i].size(); j++) { pq.push(v[i][j]); } int k = pq.top(); pq.pop(); upd(n - k + 1, -1, n); ans = get(n - k + 1) + ans; } cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1095 ms | 5120 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1095 ms | 5120 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |