QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#656015 | #4233. Reset | chuchu# | WA | 0ms | 3852kb | C++20 | 2.3kb | 2024-10-19 10:50:19 | 2024-10-19 10:50:23 |
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 = [&] (int res) -> bool {
// cerr << "------------------------\nGuess: " << res << "\n";
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<ll, 2>, vector<array<ll, 2>>, decltype(cmp1)> todo(cmp1);
priority_queue<array<ll, 2>, vector<array<ll, 2>>, decltype(cmp2)> tokill(cmp2);
for (auto& x : tsk) todo.push(x);
int cando = min(n, c);
ll time = 0;
vector<array<ll, 2>> remaining;
while (todo.size() || tokill.size()) {
while (tokill.size() < cando && todo.size()) {
auto [x, y] = todo.top(); todo.pop();
// cerr << "push " << x << " " << y << " at time " << time << endl;
tokill.push({x + y*time, y});
}
auto [t, d] = tokill.top(); tokill.pop();
// cerr << "pop " << t << " " << d << endl;
if (t / d > res) {
// cerr << "too big" << endl;
time = res;
remaining.push_back({t-d*res, d});
} else {
time = t/d;
ll rem = t % d;
// cerr << "rem " << rem << endl;
if (rem != 0) {
// cerr << "pushing to todo" << endl;
todo.push({rem, rem});
}
}
// cerr << "todo size: " << todo.size() << endl;
}
ll finaltime = 0;
for (auto [t, d] : remaining) {
// cerr << "final: " << t << " " << d << endl;
finaltime += t - d + 1;
}
return finaltime <= c;
};
int l = 0, r = 1e9;
while (l < r) {
int 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: 3564kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
3 2345 333 1 444 2 555 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
1 500 1000 2
output:
250
result:
ok single line: '250'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
3 2345 3333 5 4444 6 5555 6
output:
646
result:
ok single line: '646'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3852kb
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'