답안 #167413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167413 2019-12-08T10:07:52 Z theStaticMind Kralj (COCI16_kralj) C++14
140 / 140
844 ms 60664 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 844 ms 52944 KB Output is correct
2 Correct 571 ms 51368 KB Output is correct
3 Correct 728 ms 59256 KB Output is correct
4 Correct 757 ms 60588 KB Output is correct
5 Correct 807 ms 55620 KB Output is correct
6 Correct 615 ms 55316 KB Output is correct
7 Correct 698 ms 57528 KB Output is correct
8 Correct 565 ms 52344 KB Output is correct
9 Correct 723 ms 60408 KB Output is correct
10 Correct 766 ms 60664 KB Output is correct