QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#188806 | #7504. HearthStone | zhoukangyang# | AC ✓ | 364ms | 15936kb | C++11 | 1.1kb | 2023-09-26 14:33:04 | 2023-09-26 14:33:05 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector < int >
#define sz(a) ((int) (a).size())
#define ll long long
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a))
using namespace std;
const int N = 1 << 20;
int n;
int a[N];
priority_queue < int > ql;
priority_queue < int, vi, greater < int > > qr;
vi xl;
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
L(i, 1, n) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
ll all = 0;
ll addr = 0;
vi xl;
L(i, 1, n) {
if(a[i] > i) {
all += a[i] - i;
a[i] = i;
}
all += a[i];
ql.push(a[i]), qr.push(a[i] - addr);
while(ql.top() > qr.top() + addr) {
ll x = ql.top(), y = qr.top() + addr;
ql.pop(), qr.pop();
ql.push(y), qr.push(x - addr);
}
addr += 1;
}
while(!ql.empty()) {
all -= ql.top(), ql.pop();
}
cout << all << '\n';
return 0;
}
/*
6
1 1 1 1 1 1
6
1 1 1 3 3 3
6
4 6 8 9 2 4
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3668kb
input:
6 4 6 8 9 2 4
output:
12
result:
ok 1 number(s): "12"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
15 9 4 9 2 6 6 1 3 10 4 10 2 4 8 6
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
20 5 5 7 5 4 4 10 1 8 1 3 7 7 8 5 2 5 9 5 9
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
25 2 6 5 12 2 5 5 11 3 5 1 3 7 10 5 4 12 10 4 8 4 12 5 2 8
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
25 2 2 18 4 17 13 14 1 6 16 20 24 3 3 10 3 10 6 14 12 9 16 19 15 6
output:
9
result:
ok 1 number(s): "9"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
13 25 5 20 7 15 7 8 3 16 23 10 8 10
output:
66
result:
ok 1 number(s): "66"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
105 76 60 6 84 64 25 9 10 58 22 46 31 80 16 14 10 75 57 80 60 28 58 43 83 9 44 62 73 76 88 45 21 47 56 52 2 59 69 39 76 19 8 13 17 68 6 49 88 62 53 23 53 14 65 28 13 84 30 64 50 77 57 82 31 11 77 77 72 52 89 86 81 21 57 24 57 35 61 78 24 53 80 82 66 46 51 47 25 24 83 11 17 60 29 21 25 54 76 55 61 19...
output:
129
result:
ok 1 number(s): "129"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
500 17 5 59 21 20 16 59 8 41 79 50 72 51 45 20 45 46 86 76 28 14 22 11 82 8 23 37 16 75 29 71 52 50 89 54 8 33 65 27 31 47 59 39 13 43 6 55 68 41 78 28 56 44 55 45 46 48 54 50 5 29 52 87 87 71 33 64 6 2 35 27 39 72 48 20 69 48 23 22 87 31 26 44 80 5 22 3 82 67 39 29 58 56 81 68 12 49 30 49 68 86 69 ...
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3672kb
input:
1000 9 81 55 45 54 13 14 32 88 21 39 13 100 20 14 81 72 30 53 66 73 37 59 43 3 1 20 60 60 15 14 45 13 77 17 34 9 4 21 39 79 43 84 89 35 71 55 93 72 20 66 11 60 64 94 65 71 5 17 49 84 11 42 24 6 66 3 89 22 53 97 14 66 36 59 29 54 99 81 25 92 35 18 74 93 13 80 30 18 89 31 38 32 65 97 41 52 77 48 95 97...
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 2ms
memory: 3820kb
input:
10000 184 50 415 13 913 24 597 640 706 688 37 927 774 169 714 941 894 926 323 545 585 650 52 839 391 809 596 153 522 119 199 170 247 492 93 541 323 792 835 753 673 579 344 256 171 24 698 480 63 11 570 401 524 297 725 896 84 447 412 147 885 126 439 38 355 493 526 654 664 168 440 276 583 503 799 381 3...
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
10000 4210 3733 4488 912 894 670 496 1222 727 3271 2853 4279 3277 1468 643 2574 2062 256 3969 135 605 4426 99 187 1143 4975 4225 4887 4162 4360 207 424 391 1637 3094 946 1001 3937 3699 2433 1038 4968 2374 527 3086 2967 2366 3887 2618 4964 1844 1089 2750 1469 1685 3808 1010 2205 3388 2328 2797 3852 2...
output:
846
result:
ok 1 number(s): "846"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
3000 9265 2616 8267 9004 4633 1888 7872 6994 1512 9826 339 5028 9190 612 2462 7409 9216 5805 7323 1838 8061 458 5975 3364 17 9134 6022 5061 5202 458 5687 9301 2842 2877 9593 6199 3181 2142 8238 2053 6940 680 2303 516 760 7237 1633 9303 1402 5438 8774 1170 8819 6066 3254 9378 255 8053 768 5740 5056 1...
output:
9656961
result:
ok 1 number(s): "9656961"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3744kb
input:
4000 4295 6048 205 13966 1929 4461 13116 8417 14044 7261 4008 5424 6832 5689 10584 4612 6202 7792 1032 4184 12497 3714 37 10959 5372 359 6191 7270 6835 5083 9928 12924 2150 9973 5324 4279 6683 14201 1681 4992 2244 4234 12434 11466 6519 28 12998 13078 5864 11961 6198 3099 13428 490 6863 7501 10575 33...
output:
19583941
result:
ok 1 number(s): "19583941"
Test #14:
score: 0
Accepted
time: 303ms
memory: 15196kb
input:
1000000 80608 251073 980681 649495 561970 950614 76033 666468 116836 955978 87641 648542 279156 823327 256029 100512 154328 155177 452553 278682 409719 297297 280656 205454 605933 880725 153112 685012 442187 191814 152827 917527 560021 866825 332296 802518 781571 91031 177856 476452 98625 577021 352...
output:
174249444
result:
ok 1 number(s): "174249444"
Test #15:
score: 0
Accepted
time: 364ms
memory: 15440kb
input:
1000000 734923 276989 401041 865275 658138 885662 781455 862400 20539 147942 300911 468741 862949 278149 467363 84100 898146 814366 596848 826284 101267 758474 262831 450206 415081 565142 663885 250864 620205 598464 73611 135086 225914 630078 713599 804308 689469 866551 934034 851989 328700 534727 5...
output:
120543133
result:
ok 1 number(s): "120543133"
Test #16:
score: 0
Accepted
time: 335ms
memory: 15936kb
input:
1000000 171132 261498 584300 815166 377994 229007 359640 132393 892128 103801 807891 26464 435184 742580 511271 675591 383103 264749 70069 266488 412005 291334 734574 397566 29650 655318 897819 703256 824964 116839 462038 86141 475858 160758 451407 977618 864420 286582 276936 952053 40824 634958 758...
output:
128332022
result:
ok 1 number(s): "128332022"
Test #17:
score: 0
Accepted
time: 329ms
memory: 15492kb
input:
1000000 934499 904438 43275 2035 791405 314435 532360 791295 844656 26554 726881 799662 766547 692597 193615 49853 578112 124662 889997 835021 181222 345758 213789 629157 274232 700406 628932 438575 585964 451242 310857 49655 816956 653001 961787 635439 251496 577990 739752 578030 77042 455866 32093...
output:
170812168
result:
ok 1 number(s): "170812168"
Test #18:
score: 0
Accepted
time: 1ms
memory: 3660kb
input:
1000 8 5 16 1 17 20 12 2 5 3 20 11 11 19 8 3 19 18 11 1 9 20 8 3 7 4 16 8 11 7 18 15 2 20 18 14 2 3 19 8 5 17 1 3 4 17 4 10 17 19 11 12 6 20 9 12 3 11 8 3 20 3 5 17 1 2 5 20 19 7 7 4 2 1 3 13 2 15 12 16 12 10 7 2 11 9 19 19 12 8 11 12 17 17 3 18 8 6 7 1 13 2 2 18 3 4 16 5 3 2 17 16 19 19 8 6 5 13 17...
output:
0
result:
ok 1 number(s): "0"