Submission #139432

# Submission time Handle Problem Language Result Execution time Memory
139432 2019-07-31T17:10:27 Z Minnakhmetov Kralj (COCI16_kralj) C++14
70 / 140
803 ms 42072 KB
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 5e5 + 5;
vector<int> v[N];
int a[N], b[N];

signed main() { 
#ifdef HOME
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        v[a[i] - 1].push_back(x);
    }

    int need = 0;

    for (int i = 0; i < n; i++) {
        need += v[i].size();
        need = max(0, need - 1);
    }

    for (int i = 0; i < n; i++) {
        need += v[i].size();
        need = max(0, need - 1);
    }

    set<int> st;

    for (int i = 0; i < need; i++) {
        for (int j : v[i])
            st.insert(j);
    }

    int ans = 0;

    for (int i = need; i < n; i++) {
        for (int j : v[i])
            st.insert(j);   
        if (*st.rbegin() > b[i]) {
            st.erase(st.upper_bound(b[i]));
            ans++;
        }
        else {
            st.erase(st.begin());
        }
    }

    for (int i = 0; i < need; i++) {
        for (int j : v[i])
            st.insert(j);
        if (*st.rbegin() > b[i]) {
            st.erase(st.upper_bound(b[i]));
            ans++;
        }
        else {
            st.erase(st.begin());
        }
    }

    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 803 ms 36376 KB Output is correct
2 Correct 499 ms 35832 KB Output is correct
3 Correct 619 ms 41424 KB Output is correct
4 Correct 640 ms 42072 KB Output is correct
5 Incorrect 435 ms 19556 KB Output isn't correct
6 Correct 359 ms 20088 KB Output is correct
7 Incorrect 470 ms 22836 KB Output isn't correct
8 Incorrect 388 ms 22564 KB Output isn't correct
9 Incorrect 490 ms 23148 KB Output isn't correct
10 Incorrect 416 ms 20668 KB Output isn't correct