Task: | Greedy Game |
Sender: | zxc |
Submission time: | 2016-07-28 15:27:11 +0300 |
Language: | C++ |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.04 s | details |
#2 | WRONG ANSWER | 0.05 s | details |
#3 | WRONG ANSWER | 0.04 s | details |
#4 | WRONG ANSWER | 0.04 s | details |
#5 | WRONG ANSWER | 0.04 s | details |
#6 | WRONG ANSWER | 0.05 s | details |
#7 | WRONG ANSWER | 0.05 s | details |
#8 | WRONG ANSWER | 0.04 s | details |
#9 | WRONG ANSWER | 0.05 s | details |
#10 | WRONG ANSWER | 0.05 s | details |
#11 | WRONG ANSWER | 0.03 s | details |
#12 | WRONG ANSWER | 0.04 s | details |
#13 | WRONG ANSWER | 0.03 s | details |
#14 | WRONG ANSWER | 0.17 s | details |
#15 | WRONG ANSWER | 0.19 s | details |
#16 | WRONG ANSWER | 0.20 s | details |
#17 | WRONG ANSWER | 0.16 s | details |
#18 | WRONG ANSWER | 0.18 s | details |
#19 | WRONG ANSWER | 0.23 s | details |
#20 | WRONG ANSWER | 0.24 s | details |
#21 | WRONG ANSWER | 0.21 s | details |
#22 | WRONG ANSWER | 0.22 s | details |
#23 | WRONG ANSWER | 0.24 s | details |
#24 | WRONG ANSWER | 0.19 s | details |
#25 | WRONG ANSWER | 0.22 s | details |
#26 | WRONG ANSWER | 0.16 s | details |
#27 | WRONG ANSWER | 0.21 s | details |
#28 | WRONG ANSWER | 0.21 s | details |
#29 | WRONG ANSWER | 0.20 s | details |
#30 | WRONG ANSWER | 0.21 s | details |
Code
#include <bits/stdc++.h> #define F first #define S second using namespace std; typedef long long ll; const ll MN = 1e5+100; const ll N = 1<<17; pair<ll, ll> t[MN]; pair<ll, ll> b[MN]; ll st[2*N]; ll sisu[2*N]; ll getMin(ll k, ll l, ll r, ll x, ll y) { if(l > y || r < x) return 1e9; if(l >= x && r <= y) { return st[k]; } ll mid = (l+r)/2; ll q = getMin(k*2, l, mid, x, y); ll w = getMin(k*2+1, mid+1, r, x, y); return min(q, w) + sisu[k]; } ll add(ll k, ll l, ll r, ll x, ll y, ll v) { if(l > y || r < x) return st[k]; if(l >= x && r <= y) { sisu[k] += v; st[k] += v; return st[k]; } ll mid = (l+r)/2; ll q = add(k*2, l, mid, x, y, v); ll w = add(k*2+1, mid+1, r, x, y, v); return st[k] = q + w; } ll st2[2*N]; ll getSum(int a, int b) { a += N; b += N; ll sum = 0; for(; a <= b; a/=2, b/=2) { if(a&1) sum += st2[a++]; if(~b&1) sum += st2[b--]; } return sum; } void addValue(int a, int v) { a += N; for(; a; a/=2) { st2[a] += v; } } ll pos[MN]; int main() { ll n; cin>>n; for(ll i = 0; i< n; ++i) { cin>>t[i].F; t[i].S = i; } for(int i = 0; i < n; ++i) { cin>>b[i].F; b[i].S = i; } sort(t, t+n); for(ll i = 0; i < n; ++i) { pos[t[i].S] = i; } for(int i = 0; i < n; ++i) { cout<<pos[i]<<' '; } for(int i = 0; i < 2*N; ++i) { st[i] = 1e9; } cout<<'\n'; sort(b, b+n); long long ans = 0; for(ll i = n-1; i >= 0; --i) { ll x = pos[b[i].S]; //cout<<x<<' '<<b[i].F<<' '<<b[i].S<<'\n'; if(x == n-1) continue; int q = getSum(x+1, N-1); if(getMin(1, 0, N-1,0, x-1) != 0 && (q)*2 < (n-x-1)) { add(1, 0, N-1, 0, x-1, -1); int jalj = (n-x-1) - (q)*2-1; //cout<<"hei "<<b[i].F<<' '<<q<<' '<<jalj<<'\n'; add(1, 0, N-1, x, x, jalj); addValue(x, 1); ans += b[i].F; } } cout<<ans<<'\n'; }
Test details
Test 1
Verdict: WRONG ANSWER
input |
---|
5 1 2 3 4 5 2 3 4 5 6 |
correct output |
---|
8 |
user output |
---|
0 1 2 3 4 8 |
Test 2
Verdict: WRONG ANSWER
input |
---|
10 1 1 1 1 1 1 1 1 1 1 2 3 9 5 6 6 1 2 3 4 |
correct output |
---|
17 |
user output |
---|
0 1 2 3 4 5 6 7 8 9 30 |
Test 3
Verdict: WRONG ANSWER
input |
---|
15 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
7 |
user output |
---|
0 1 2 3 4 5 6 7 8 9 10 11 12 1... |
Test 4
Verdict: WRONG ANSWER
input |
---|
15 2 4 2 8 6 6 5 6 4 10 9 3 10 7 ... |
correct output |
---|
60 |
user output |
---|
0 3 1 10 6 7 5 8 4 13 12 2 14 ... |
Test 5
Verdict: WRONG ANSWER
input |
---|
15 3 8 6 9 1 5 1 9 3 10 1 10 9 8 ... |
correct output |
---|
47 |
user output |
---|
4 8 7 10 0 6 1 11 5 13 2 14 12... |
Test 6
Verdict: WRONG ANSWER
input |
---|
15 2 6 4 9 8 3 8 7 1 8 8 7 5 6 8 7 6 4 9 3 8 9 5 3 10 2 2 4 6 3 |
correct output |
---|
46 |
user output |
---|
1 5 3 14 9 2 10 7 0 11 12 8 4 ... |
Test 7
Verdict: WRONG ANSWER
input |
---|
15 7 10 8 8 6 10 5 1 7 3 9 4 7 9 ... |
correct output |
---|
56 |
user output |
---|
6 13 9 10 4 14 3 0 7 1 11 2 8 ... |
Test 8
Verdict: WRONG ANSWER
input |
---|
15 9 8 7 7 4 6 4 10 3 7 5 9 5 9 5 3 6 7 2 9 8 3 3 7 5 6 7 9 3 8 |
correct output |
---|
55 |
user output |
---|
11 10 7 8 1 6 2 14 0 9 3 12 4 ... |
Test 9
Verdict: WRONG ANSWER
input |
---|
15 684567283 992849846 97315816 3... |
correct output |
---|
5346487014 |
user output |
---|
10 14 0 6 3 1 2 5 12 11 7 4 13... |
Test 10
Verdict: WRONG ANSWER
input |
---|
15 220108915 735849670 3920201 84... |
correct output |
---|
4369763599 |
user output |
---|
3 9 0 1 6 7 4 5 2 8 13 11 14 1... |
Test 11
Verdict: WRONG ANSWER
input |
---|
15 428748595 949568430 413698361 ... |
correct output |
---|
5262225140 |
user output |
---|
6 13 5 11 8 0 3 12 7 2 14 1 10... |
Test 12
Verdict: WRONG ANSWER
input |
---|
15 310486323 634006126 326650297 ... |
correct output |
---|
5825473032 |
user output |
---|
3 9 5 2 11 4 8 13 10 12 7 6 0 ... |
Test 13
Verdict: WRONG ANSWER
input |
---|
15 865322099 789162758 742776009 ... |
correct output |
---|
5028684388 |
user output |
---|
13 10 9 7 1 6 8 4 11 0 3 5 14 ... |
Test 14
Verdict: WRONG ANSWER
input |
---|
100000 1 5 7 1 6 8 1 7 9 2 7 7 6 1 8 ... |
correct output |
---|
387044 |
user output |
---|
0 39931 59972 1 49921 69940 2 ... |
Test 15
Verdict: WRONG ANSWER
input |
---|
100000 10 6 1 4 1 8 5 4 8 10 5 8 7 5 ... |
correct output |
---|
388046 |
user output |
---|
90021 49863 0 29866 1 69993 39... |
Test 16
Verdict: WRONG ANSWER
input |
---|
100000 6 1 1 6 7 8 10 6 7 6 8 7 6 5 3... |
correct output |
---|
387631 |
user output |
---|
49871 0 1 49872 60059 70109 90... |
Test 17
Verdict: WRONG ANSWER
input |
---|
100000 9 2 5 7 5 8 5 3 4 10 5 6 10 2 ... |
correct output |
---|
387600 |
user output |
---|
80007 10035 39916 60017 39917 ... |
Test 18
Verdict: WRONG ANSWER
input |
---|
100000 8 7 4 7 3 6 2 6 1 2 7 5 1 5 5 ... |
correct output |
---|
387928 |
user output |
---|
70167 59984 30075 59985 20035 ... |
Test 19
Verdict: WRONG ANSWER
input |
---|
100000 329395763 605200206 806179577 ... |
correct output |
---|
37487670627833 |
user output |
---|
33184 60450 80526 59669 16277 ... |
Test 20
Verdict: WRONG ANSWER
input |
---|
100000 595917875 55389390 744521721 4... |
correct output |
---|
37446270419509 |
user output |
---|
59584 5609 74529 46605 17974 9... |
Test 21
Verdict: WRONG ANSWER
input |
---|
100000 535538034 976297510 186037641 ... |
correct output |
---|
37452666188784 |
user output |
---|
53654 97674 18622 25174 29738 ... |
Test 22
Verdict: WRONG ANSWER
input |
---|
100000 148256243 367924566 130727336 ... |
correct output |
---|
37441139105851 |
user output |
---|
14633 36640 12936 95318 50872 ... |
Test 23
Verdict: WRONG ANSWER
input |
---|
100000 434072499 230270558 578590809 ... |
correct output |
---|
37528719082827 |
user output |
---|
43286 23031 57996 57454 81963 ... |
Test 24
Verdict: WRONG ANSWER
input |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
375239 |
user output |
---|
0 1 2 3 4 5 6 7 8 9 10 11 12 1... |
Test 25
Verdict: WRONG ANSWER
input |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
37477679133533 |
user output |
---|
0 1 2 3 4 5 6 7 8 9 10 11 12 1... |
Test 26
Verdict: WRONG ANSWER
input |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
375514 |
user output |
---|
0 1 2 3 4 5 6 7 8 9 10 11 12 1... |
Test 27
Verdict: WRONG ANSWER
input |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
37505905982098 |
user output |
---|
0 1 2 3 4 5 6 7 8 9 10 11 12 1... |
Test 28
Verdict: WRONG ANSWER
input |
---|
100000 100000 100000 100000 100000 10... |
correct output |
---|
5000000000 |
user output |
---|
0 1 2 3 4 5 6 7 8 9 10 11 12 1... |
Test 29
Verdict: WRONG ANSWER
input |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
2500000000 |
user output |
---|
0 1 2 3 4 5 6 7 8 9 10 11 12 1... |
Test 30
Verdict: WRONG ANSWER
input |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
3750025000 |
user output |
---|
0 1 2 3 4 5 6 7 8 9 10 11 12 1... |