Submission #163050

# Submission time Handle Problem Language Result Execution time Memory
163050 2019-11-11T07:48:14 Z _qVp_ Kralj (COCI16_kralj) C++14
140 / 140
919 ms 53164 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair < int, int > II;
const int md = 5e5 + 10;

int n;
int a[md], b[md], pre[md];
vector < int > adj[md];

int solve(int start) {
    int res = 0;
    set < int > S;
    for(int i = start, j = 1; j <= n; j++, i = i % n + 1) {
        for(int j = 0; j < adj[i].size(); j++)
            S.insert(adj[i][j]);
        set < int > :: iterator it = S.upper_bound(b[i]);
        if (it == S.end()) 
            S.erase(S.begin());
        else {
            S.erase(it);
            res++;
        }
    }
    return res;
}

int main() {
    //freopen("test.in", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        pre[i] = -1;
    }
    for(int i = 1; i <= n; i++)
        cin >> b[i];
    II start = II(1e9, 1e9);
    for(int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        adj[a[i]].push_back(x); 
        //cout << a[i] << " " << x << endl;
        pre[a[i]]++;
    }
    for(int i = 1; i <= n; i++) {
        pre[i] += pre[i - 1];
        start = min(start, II(pre[i], i));
    }
    cout << solve(start.second % n + 1);
    return 0;
}

Compilation message

kralj.cpp: In function 'int solve(int)':
kralj.cpp:16:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < adj[i].size(); j++)
                        ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 919 ms 45804 KB Output is correct
2 Correct 531 ms 44652 KB Output is correct
3 Correct 702 ms 52588 KB Output is correct
4 Correct 723 ms 53164 KB Output is correct
5 Correct 474 ms 32492 KB Output is correct
6 Correct 430 ms 32504 KB Output is correct
7 Correct 558 ms 36344 KB Output is correct
8 Correct 477 ms 34544 KB Output is correct
9 Correct 591 ms 37504 KB Output is correct
10 Correct 464 ms 33912 KB Output is correct