QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#496610#4233. ResetCelestialCoder#WA 1ms5868kbC++202.1kb2024-07-28 13:49:362024-07-28 13:49:36

Judging History

你现在查看的是最新测评结果

  • [2024-07-28 13:49:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5868kb
  • [2024-07-28 13:49:36]
  • 提交

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'