QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#656042 | #4233. Reset | chuchu# | WA | 0ms | 3664kb | C++20 | 1.9kb | 2024-10-19 11:00:59 | 2024-10-19 11:01:00 |
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 cmp1 = [] (auto& x, auto& y) {
return x[1] < y[1];
};
auto cmp2 = [] (auto& x, auto& y) {
return x[0] / x[1] > y[0] / y[1];
};
priority_queue<array<__int128_t, 2>, vector<array<__int128_t, 2>>, decltype(cmp1)> todo(cmp1);
priority_queue<array<__int128_t, 2>, vector<array<__int128_t, 2>>, decltype(cmp2)> tokill(cmp2);
for (auto& x : tsk) todo.push({x[0], x[1]});
int cando = min(n, c);
__int128_t time = 0;
vector<array<__int128_t, 2>> remaining;
while (todo.size() || tokill.size()) {
while (tokill.size() < cando && todo.size()) {
auto [x, y] = todo.top(); todo.pop();
tokill.push({x + y*time, y});
}
auto [t, d] = tokill.top(); tokill.pop();
if (t / d > res) {
time = res;
remaining.push_back({t-d*res, d});
} else {
time = t/d;
__int128_t rem = t % d;
if (rem != 0) {
todo.push({rem, rem});
}
}
}
ll finaltime = 0;
for (auto [t, d] : remaining) {
finaltime += t - d + 1;
}
return finaltime <= 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;
}
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: 3636kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
3 2345 333 1 444 2 555 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
1 500 1000 2
output:
250
result:
ok single line: '250'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
3 2345 3333 5 4444 6 5555 6
output:
646
result:
ok single line: '646'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3632kb
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: -100
Wrong Answer
time: 0ms
memory: 3568kb
input:
8 6 40 10 40 10 40 10 40 10 40 10 20 5 7 3 5 3
output:
5
result:
wrong answer 1st lines differ - expected: '4', found: '5'