# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167413 | theStaticMind | Kralj (COCI16_kralj) | C++14 | 844 ms | 60664 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |