Submission #139435

#TimeUsernameProblemLanguageResultExecution timeMemory
139435MinnakhmetovKralj (COCI16_kralj)C++14
140 / 140
770 ms42344 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...