QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#656450 | #4233. Reset | chuchu | WA | 4236ms | 22900kb | C++20 | 2.6kb | 2024-10-19 13:02:50 | 2024-10-19 13:02:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
int n, c; cin >> n >> c;
vector<array<ll, 2>> tsk;
for (int i = 0; i < n; ++i) {
int t, d; cin >> t >> d;
tsk.push_back({t, d});
}
auto can = [&] (ll res) -> bool {
auto cmp = [] (auto x, auto y) {
if (x[1] == y[1]) return x[0] > y[0];
return x[1] < y[1];
};
priority_queue<array<__int128_t, 2>, vector<array<__int128_t, 2>>, decltype(cmp)> pq(cmp);
for (auto& t : tsk) pq.push({t[0], t[1]});
__int128_t row = 0, col = 0;
__int128_t fintim = 0;
res++;
while (pq.size()) {
auto [t, d] = pq.top(); pq.pop();
__int128_t rem = t % d;
__int128_t need = t/d;
if (col + need >= res) {
fintim++;
if (row == c-1) {
pq.push({t - d * (res - col), min(t - d * (res - col), d)});
col = res; ++row;
break;
} else if (need > res) {
row++;
t -= (d * res);
fintim += t;
} else {
// need <= res, and we can fit
if (rem) {
if (need == res) {
fintim += rem;
fintim--;
row++;
} else {
col += need; col -= res;
row++;
pq.push({rem, rem});
}
} else {
// no remainder
col += need; col -= res;
row++;
}
}
} else {
col += need;
if (rem) {
pq.push({rem, rem});
}
}
}
// cout << "-----\n";
while (pq.size()) {
auto [t, d] = pq.top(); pq.pop();
fintim += t;
}
// cout << (ll)fintim << endl;
return fintim <= c;
};
ll l = 0, r = 1e16;
while (l < r) {
ll m = l + (r - l) / 2;
if (can(m)) r = m;
else l = m + 1;
}
cout << l << endl;
// for (int i = 3; i <= 3; ++i) {
// cerr << i << " " << can(i) << endl;
// }
}
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int t = 1;
// cin >> t;
while (t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
3 2345 333 1 444 2 555 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
1 500 1000 2
output:
250
result:
ok single line: '250'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
3 2345 3333 5 4444 6 5555 6
output:
646
result:
ok single line: '646'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
8 6 40 10 40 10 40 10 40 10 40 10 20 5 4 3 5 3
output:
4
result:
ok single line: '4'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
8 6 40 10 40 10 40 10 40 10 40 10 20 5 7 3 5 3
output:
4
result:
ok single line: '4'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
5 4 29 8 30 7 2000 1000 2000 1000 2000 1000
output:
3
result:
ok single line: '3'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
27 19 21 5 14 5 14 5 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000
output:
4
result:
ok single line: '4'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
24 21 25 8 13 7 13 7 13 7 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000
output:
3
result:
ok single line: '3'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
4 2 10 10 10 10 10 10 9 2
output:
3
result:
ok single line: '3'
Test #14:
score: 0
Accepted
time: 477ms
memory: 13048kb
input:
110000 60000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 10000...
output:
99999
result:
ok single line: '99999'
Test #15:
score: 0
Accepted
time: 732ms
memory: 21560kb
input:
200000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 10000...
output:
199999999999999
result:
ok single line: '199999999999999'
Test #16:
score: 0
Accepted
time: 3740ms
memory: 21156kb
input:
200000 7 966486041 28 936158040 29 991239679 47 988279269 31 905558493 68 998009820 40 901181342 66 925252807 10 995161072 3 947576761 21 980670741 66 931584704 3 944714227 42 992178536 6 905079737 39 982672468 87 963094272 21 919244645 48 935633595 3 903091417 4 923453539 72 916293313 82 981382022 ...
output:
1405907290168
result:
ok single line: '1405907290168'
Test #17:
score: 0
Accepted
time: 3865ms
memory: 22180kb
input:
200000 313 955333176 37 901868728 50 941539297 29 986447408 44 991503201 16 960466782 13 941404760 26 906572773 27 983407691 42 968036098 75 978785905 2 930572618 67 968054047 14 972769762 39 903513789 23 966791626 84 992080584 65 976672158 15 912399245 35 961103319 25 920979048 64 959902065 72 9685...
output:
31397952846
result:
ok single line: '31397952846'
Test #18:
score: 0
Accepted
time: 2775ms
memory: 20964kb
input:
200000 10 23 21 17 5 5 5 9 2 29 24 14 7 24 23 30 8 10 10 29 27 1 1 3 2 18 7 17 12 26 3 13 6 7 4 28 20 5 1 16 3 24 5 22 4 27 11 11 5 1 1 12 4 1 1 12 3 30 5 26 24 11 9 21 19 1 1 4 4 8 1 29 22 10 8 3 1 24 12 7 7 25 18 11 10 20 19 20 19 20 10 27 26 2 2 12 7 24 18 19 15 19 10 11 4 12 4 2 1 27 9 3 3 19 5 ...
output:
70162
result:
ok single line: '70162'
Test #19:
score: 0
Accepted
time: 2475ms
memory: 22304kb
input:
200000 10 4 1 8 4 11 4 15 2 3 3 7 3 14 3 27 4 17 4 4 4 11 5 19 1 29 4 9 5 2 1 30 5 5 1 27 5 20 2 6 5 3 3 30 3 18 2 13 5 16 3 21 3 8 3 17 4 10 5 16 3 8 2 16 3 8 4 4 4 2 2 8 3 30 4 15 1 21 3 19 3 12 5 3 1 23 2 9 3 15 5 4 2 11 3 15 4 5 3 1 1 28 2 12 3 15 3 5 1 6 5 3 1 4 3 18 2 26 4 29 5 7 3 19 2 13 1 1...
output:
147252
result:
ok single line: '147252'
Test #20:
score: 0
Accepted
time: 2847ms
memory: 22624kb
input:
200000 100 18 11 12 3 10 6 28 26 17 2 2 2 6 5 15 12 18 7 26 8 29 18 6 1 20 10 14 4 3 2 3 2 4 2 7 6 7 4 9 2 21 19 11 8 23 19 3 2 10 10 17 12 24 21 12 10 30 22 29 17 12 5 5 4 9 3 20 12 7 6 17 5 5 5 30 4 8 2 29 1 30 25 16 13 25 23 2 1 24 23 10 3 10 10 7 4 24 13 1 1 26 26 3 2 10 3 17 6 14 7 28 18 3 1 17...
output:
7021
result:
ok single line: '7021'
Test #21:
score: 0
Accepted
time: 2487ms
memory: 21660kb
input:
200000 100 3 2 6 3 18 4 14 5 4 1 1 1 25 1 22 1 15 1 2 2 16 2 3 2 11 2 29 4 21 3 13 2 4 1 7 3 13 5 5 2 13 3 19 2 8 3 3 2 22 3 16 1 28 1 26 4 19 3 7 5 22 1 10 3 19 1 5 3 2 2 18 1 5 1 16 2 12 3 20 1 12 5 25 5 20 3 23 2 17 4 30 3 24 1 24 4 16 1 18 1 21 3 9 4 7 5 28 4 1 1 15 2 24 3 1 1 14 1 26 1 27 3 28 ...
output:
14737
result:
ok single line: '14737'
Test #22:
score: 0
Accepted
time: 2831ms
memory: 22492kb
input:
200000 1000 13 1 29 7 22 15 17 12 30 25 20 7 28 12 13 13 8 5 22 7 9 6 20 15 2 2 23 16 13 2 21 1 27 9 1 1 13 5 18 9 28 2 28 8 12 12 10 6 2 2 19 16 4 4 14 14 10 5 7 1 16 16 26 14 5 2 20 12 5 5 3 3 10 7 22 21 7 6 4 3 21 17 22 12 7 5 6 6 17 6 16 6 30 6 22 4 29 16 4 3 29 3 26 17 21 15 21 20 14 13 27 24 1...
output:
698
result:
ok single line: '698'
Test #23:
score: 0
Accepted
time: 2448ms
memory: 21256kb
input:
200000 1000 27 5 2 2 29 4 9 2 16 4 15 3 29 3 1 1 21 2 2 1 21 3 17 4 12 2 26 2 1 1 8 5 29 2 5 3 4 3 9 4 5 5 30 2 11 4 20 5 25 1 22 2 21 1 1 1 5 2 13 4 26 1 5 2 7 3 21 2 27 5 17 3 24 2 25 1 26 4 15 2 5 1 15 5 26 2 6 5 27 4 3 1 19 5 27 4 24 5 3 1 17 4 25 5 1 1 20 2 22 4 12 5 1 1 6 3 25 1 15 1 22 2 10 2...
output:
1474
result:
ok single line: '1474'
Test #24:
score: 0
Accepted
time: 2797ms
memory: 21516kb
input:
200000 998642531 14 6 13 3 2 1 9 6 15 12 10 1 11 9 21 13 23 8 29 8 28 26 1 1 27 5 17 3 14 14 22 11 27 19 5 2 9 3 2 1 11 4 9 3 8 5 28 12 12 7 29 12 19 5 29 16 24 3 20 10 2 2 6 3 9 5 6 4 3 2 18 3 16 3 27 5 14 14 29 23 21 17 22 13 1 1 13 2 21 7 13 1 21 16 11 1 18 8 28 17 14 6 24 8 30 15 29 4 4 2 13 12 ...
output:
0
result:
ok single line: '0'
Test #25:
score: 0
Accepted
time: 4236ms
memory: 22900kb
input:
200000 10 3684 3080 3014 1370 3226 2869 4168 3400 3744 45 4280 670 4898 1215 4699 1387 3103 2201 4357 1267 4602 1765 3290 1180 3556 3370 4198 3434 3743 3324 4592 4451 3328 2499 4848 2244 3879 2853 3676 2630 4758 3917 3057 1758 3045 279 4784 3965 4530 4183 4435 1460 3239 978 4034 269 4046 3652 3626 2...
output:
188403
result:
ok single line: '188403'
Test #26:
score: 0
Accepted
time: 4174ms
memory: 22152kb
input:
200000 100 3019 973 3932 1011 3415 2658 3428 2971 3566 1447 4647 2270 4083 135 3876 3207 3505 2148 3979 3087 3314 1757 3116 1 3785 3297 3220 2212 3585 3462 3583 3195 4654 3563 3951 704 3535 1229 3941 1769 3804 3085 4218 1581 3241 2950 3445 2551 4753 25 4583 1820 4466 2945 3572 2641 3500 503 4403 180...
output:
18881
result:
ok single line: '18881'
Test #27:
score: 0
Accepted
time: 3704ms
memory: 22572kb
input:
200000 100 3294 37 3313 44 3463 9 3349 46 4444 11 3206 16 3046 16 3592 32 4838 50 4871 40 3105 8 3646 41 4136 30 4592 3 4921 2 3218 24 4452 30 3038 5 3604 22 4593 7 4475 20 3372 16 3014 19 4959 42 4863 45 3607 31 4304 48 3682 25 3651 16 3586 10 3478 17 4524 25 4611 41 4411 47 3228 14 3786 35 4114 50...
output:
721052
result:
ok single line: '721052'
Test #28:
score: -100
Wrong Answer
time: 4014ms
memory: 20764kb
input:
200000 1000 3760 3035 4707 305 3581 1906 4963 787 4825 3243 3176 750 4163 45 3109 1115 3249 864 4367 3432 3858 1478 3291 689 3421 2877 3092 719 4735 3136 4462 781 3092 2834 3907 1499 4234 4135 3777 1128 4546 1996 3986 1907 4808 4629 4907 4167 3770 947 3589 173 3438 1497 4594 4389 3067 1223 4668 4087...
output:
4751
result:
wrong answer 1st lines differ - expected: '4698', found: '4751'