Submission #167413

#TimeUsernameProblemLanguageResultExecution timeMemory
167413theStaticMindKralj (COCI16_kralj)C++14
140 / 140
844 ms60664 KiB
#include<bits/stdc++.h> #define mp make_pair #define pb push_back #define ii pair<int,int> #define all(x) (x).begin(),(x).end() #define INF 100000000000000000 #define modulo 1000000007 #define mod 998244353 //#define int long long int using namespace std; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("q.gir","r",stdin); // freopen("q.cik","w",stdout); int n,ans=0; cin>>n; vector<int>A(n); vector<int>P(n); vector<int>V(n); vector<int>cnt(n,0); for(int i=0;i<n;i++){ cin>>A[i];A[i]--; cnt[A[i]]++; } for(int i=0;i<n;i++)cin>>P[i]; for(int i=0;i<n;i++)cin>>V[i]; int t=0,ind=0; while(t<n){ int c=cnt[t]; int w=t; while(c>0){ c--; if(c==0)break; w++; if(w>=n){ ind=t; break; } c+=cnt[w]; } t=w+1; } multiset<int> data[n]; for(int i=0;i<n;i++){ data[A[i]].insert(V[i]); } for(int k=0;k<n;k++,ind=(ind+1)%n){ multiset<int>::iterator itr=data[ind].upper_bound(P[ind]); if(itr==data[ind].end()){ data[ind].erase(data[ind].begin()); } else{ data[ind].erase(itr); ans++; } int y=(ind+1)%n; if(data[ind].size()>data[y].size())swap(data[ind],data[y]); for(itr=data[ind].begin();itr!=data[ind].end();itr++){ data[y].insert(*itr); } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...