Submission #139435

# Submission time Handle Problem Language Result Execution time Memory
139435 2019-07-31T17:15:53 Z Minnakhmetov Kralj (COCI16_kralj) C++14
140 / 140
770 ms 42344 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 stock = 0;

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

    int start;

    for (int i = 0; i < n; i++) {
        stock += v[i].size();
        stock = max(0, stock - 1);
        if (stock == 0) {
            start = (i + 1) % n;
            break;
        }
    }

    set<int> st;

    int ans = 0;

    for (int i = start; 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 < start; 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;
}

Compilation message

kralj.cpp: In function 'int main()':
kralj.cpp:43:9: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int start;
         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 770 ms 36288 KB Output is correct
2 Correct 480 ms 35816 KB Output is correct
3 Correct 623 ms 41448 KB Output is correct
4 Correct 654 ms 42344 KB Output is correct
5 Correct 413 ms 19740 KB Output is correct
6 Correct 354 ms 20128 KB Output is correct
7 Correct 469 ms 22904 KB Output is correct
8 Correct 401 ms 22772 KB Output is correct
9 Correct 492 ms 23272 KB Output is correct
10 Correct 426 ms 20748 KB Output is correct