Submission #266123

# Submission time Handle Problem Language Result Execution time Memory
266123 2020-08-15T06:37:34 Z shrek12357 Kralj (COCI16_kralj) C++14
140 / 140
902 ms 54988 KB
#include<bits/stdc++.h>
using namespace std;
 
 
const int N = 5e5 + 5;
 
 
 
int n, a[N], p[N], v[N], pref[N];
vector < int > g[N];
multiset < int > q;
 
 
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> p[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> v[i];
        pref[a[i]] += 1;
        g[a[i]].push_back(v[i]);
    }
    pair < int, int > mn = make_pair(N, N);
    for(int i = 1; i <= n; i++){
        pref[i] += pref[i - 1];
        mn = min(mn, make_pair(pref[i] - i, i));
    }
    int pos = mn.second;
    if(pos == n){
        pos = 1;
    }
    else{
        pos += 1;
    }
    int ans = 0;
    for(int i = pos, j = 1; j <= n; i = (i == n ? 1 : i + 1), j++){
        for(auto it : g[i]){
            q.insert(it);
        }
        auto it = q.upper_bound(p[i]);
        if(it == q.end()){
            q.erase(q.begin());
        }
        else{
            q.erase(it);
            ans += 1;
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 902 ms 47464 KB Output is correct
2 Correct 449 ms 46056 KB Output is correct
3 Correct 598 ms 54368 KB Output is correct
4 Correct 568 ms 54988 KB Output is correct
5 Correct 395 ms 34388 KB Output is correct
6 Correct 349 ms 33968 KB Output is correct
7 Correct 434 ms 38008 KB Output is correct
8 Correct 365 ms 36088 KB Output is correct
9 Correct 471 ms 39688 KB Output is correct
10 Correct 382 ms 35832 KB Output is correct