QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#496610 | #4233. Reset | CelestialCoder# | WA | 1ms | 5868kb | C++20 | 2.1kb | 2024-07-28 13:49:36 | 2024-07-28 13:49:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n, c;
pair<int, int> arr[200001];
long long s[200001];
int tmp[200001];
int check(long long threshold) {
priority_queue<pair<int, int>> tasks;
for (int i = 1; i <= n; ++i) {
tasks.emplace(arr[i].first, i);
tmp[i] = arr[i].first;
s[i] = -1;
}
priority_queue<pair<long long, int>> pq;
for (int i = 1; i <= min(c, n); ++i) {
int idx = tasks.top().second;
s[idx] = 0;
pq.emplace(-(arr[idx].second / arr[idx].first), idx);
tasks.pop();
}
long long r = 0;
while (!pq.empty() && r <= threshold) {
long long next_r = -pq.top().first;
int idx = pq.top().second;
pq.pop();
if (next_r > threshold) {
break;
}
if (tmp[idx] >= arr[idx].first) {
tmp[idx] %= arr[idx].first;
if (tmp[idx])
tasks.emplace(tmp[idx], idx);
} else {
tmp[idx] = 0;
}
while (!tasks.empty() && pq.size() <= c) {
int d = tasks.top().first;
int target = tasks.top().second;
tasks.pop();
if (s[target] == -1)
s[target] = next_r;
pq.emplace(-(tmp[target] / d + next_r), target);
}
r = next_r;
}
long long v = 0;
for (int i = 1; i <= n; ++i) {
if (s[i] == -1)
v += tmp[i];
if (!tmp[i])
continue;
long long d = threshold - s[i] + 1;
long long decr = d * arr[i].first;
v += max(1LL, arr[i].second - decr + 1);
}
return v <= c;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> c;
for (int i = 1; i <= n; ++i) {
int t, d;
cin >> t >> d;
arr[i] = {d, t};
}
long long low = 0, high = 1'000'000'000'000'000'101ll;
while (low < high) {
long long mid = low + high >> 1;
if (check(mid))
high = mid;
else
low = mid + 1;
}
cout << low;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5540kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5660kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5580kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5532kb
input:
3 2345 333 1 444 2 555 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5652kb
input:
1 500 1000 2
output:
250
result:
ok single line: '250'
Test #6:
score: 0
Accepted
time: 1ms
memory: 5512kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: 0
Accepted
time: 1ms
memory: 5868kb
input:
3 2345 3333 5 4444 6 5555 6
output:
646
result:
ok single line: '646'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5604kb
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: 1ms
memory: 5832kb
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'