QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#656348#4233. Resetchuchu#WA 1ms3796kbC++202.4kb2024-10-19 12:32:472024-10-19 12:32:48

Judging History

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

  • [2024-10-19 12:32:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3796kb
  • [2024-10-19 12:32:47]
  • 提交

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;
                            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});
                }
            }
        }

        while (pq.size()) {
            auto [t, d] = pq.top(); pq.pop();
            fintim += t;
        }
        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;
}

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: 1ms
memory: 3516kb

input:

3 5
17 5
5 2
15 4

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

2 1345
1344 1
10 10

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

1 1000000000
1000000000 1

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3472kb

input:

3 2345
333 1
444 2
555 3

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

1 500
1000 2

output:

250

result:

ok single line: '250'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3520kb

input:

1 499
1000 2

output:

250

result:

ok single line: '250'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

3 2345
3333 5
4444 6
5555 6

output:

646

result:

ok single line: '646'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3524kb

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: 3624kb

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: -100
Wrong Answer
time: 0ms
memory: 3520kb

input:

5 4
29 8
30 7
2000 1000
2000 1000
2000 1000

output:

4

result:

wrong answer 1st lines differ - expected: '3', found: '4'