# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
485388 | Habitus | Kralj (COCI16_kralj) | C++14 | 566 ms | 68104 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 ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dec(x, y) fixed << setprecision((y)) << (x)
#define xx first
#define yy second
#define srt(v) sort((v).begin(), (v).end())
#define srtr(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define popb pop_back
#define sz(a) (int)(a).size()
#define len(a) (int)(a).length()
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int n, a[500002], p[500002], v[500002], kolko[500002];
set<int> s[500002];
int main() {
ios;
cin >> n;
for(int i=1; i<=n; i++) {
cin >> a[i];
kolko[a[i]]++;
}
for(int i=1; i<=n; i++) cin >> p[i];
for(int i=1; i<=n; i++) {
cin >> v[i];
s[a[i]].insert(v[i]);
}
int maxi=0, tren=0;
for(int i=n; i>=1; i--) {
tren+=kolko[i]-1;
maxi=max(maxi, tren);
}
int taj;
if(maxi<=0) {
taj=1;
}
else {
for(int i=1; i<n; i++) {
maxi+=kolko[i]-1;
if(maxi<=0) {
taj=i+1;
break;
}
}
}
tren=taj;
int uk=0;
for(int i=taj; i<taj+n; i++) {
int ii=(i-1)%n+1;
if(sz(s[ii])>sz(s[tren])) {
for(auto x:s[tren]) s[ii].insert(x);
tren=ii;
}
else if(tren!=ii) {
for(auto x:s[ii]) s[tren].insert(x);
}
auto it=s[tren].lower_bound(p[ii]);
if(it==s[tren].end()) s[tren].erase(s[tren].begin());
else {
uk++;
s[tren].erase(it);
}
}
cout << uk;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |