QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106744#4233. ResetzaxwellmenTL 66ms7040kbC++202.2kb2023-05-19 01:24:032023-05-19 01:24:07

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-19 01:24:07]
  • 评测
  • 测评结果:TL
  • 用时:66ms
  • 内存:7040kb
  • [2023-05-19 01:24:03]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

typedef pair<int, int> pi;
typedef double db;
typedef vector<db> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<vvvd> vvvvd;
typedef long long ll;
typedef array<int, 3> ai;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define mp make_pair
#define rsz resize
#define pb push_back
#define F first 
#define S second 

int n, c, pre;
ll cur, sub, l, r, ans;
vector<bool> fin;
vector<int> t, d, cnt;
vector<ai> events;
set<pi> s;

ll dec(ll tm) {
    fill(fin.begin(), fin.end(), false);
    fill(cnt.begin(), cnt.end(), 0);
    ll dec = 0, spots = tm * c;
    for (ai e : events) {
        if (e[2] >= n && !fin[e[2]-n]) continue;
        ll take = min({tm - cnt[e[2]%n], spots, (ll)e[1]});
        dec += e[0] * take;
        spots -= take;
        cnt[e[2]%n] += take;
        if (e[2] < n && take == e[1]) fin[e[2]] = true;
    }
    return dec;
}
bool check(ll tm) {
    if (cur-dec(tm) <= c) return true;
    return false;
}

int main() {
    cin.tie(0) -> sync_with_stdio(0);
    cin >> n >> c;
    t.rsz(n); d.rsz(n);
    F0R(i, n) {
        cin >> t[i] >> d[i];
        t[i] = t[i] - d[i] + 1;
        cur += t[i];
        if (t[i] % d[i] == 0) {
            ai nxt = {d[i], (t[i] / d[i])-1, i};
            events.pb(nxt);
            nxt = {d[i] - 1, 1, i+n};
            events.pb(nxt);
            nxt = {1, 1, i+n+n};
            events.pb(nxt);
        } else {
            ai nxt = {d[i], t[i] / d[i], i};
            events.pb(nxt);
            nxt = {t[i] % d[i], 1, i+n};
            events.pb(nxt);
        }
        r += t[i]/d[i] + 1;
    }
    sort(events.begin(), events.end());
    reverse(events.begin(), events.end());
    // for (ai e : events) cout << e[0] << ' ' << e[1] << ' ' << e[2] << '\n';
    if (cur <= c) {
        cout << "0\n";
        return 0;
    }
    fin.assign(2*n, false);
    cnt.assign(n, 0);
    while (l <= r) {
        int mid = (l+r)/2;
        if (check(mid)) {
            ans = mid;
            r = mid-1;
        } else l = mid+1;
    }
    cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3396kb

input:

3 5
17 5
5 2
15 4

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3476kb

input:

2 1345
1344 1
10 10

output:

0

result:

ok single line: '0'

Test #3:

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

input:

1 1000000000
1000000000 1

output:

0

result:

ok single line: '0'

Test #4:

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

input:

3 2345
333 1
444 2
555 3

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3400kb

input:

1 500
1000 2

output:

250

result:

ok single line: '250'

Test #6:

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

input:

1 499
1000 2

output:

250

result:

ok single line: '250'

Test #7:

score: 0
Accepted
time: 2ms
memory: 3352kb

input:

3 2345
3333 5
4444 6
5555 6

output:

646

result:

ok single line: '646'

Test #8:

score: 0
Accepted
time: 2ms
memory: 3480kb

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: 2ms
memory: 3476kb

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: 0
Accepted
time: 0ms
memory: 3400kb

input:

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

output:

3

result:

ok single line: '3'

Test #11:

score: 0
Accepted
time: 2ms
memory: 3408kb

input:

27 19
21 5
14 5
14 5
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000

output:

4

result:

ok single line: '4'

Test #12:

score: 0
Accepted
time: 2ms
memory: 3480kb

input:

24 21
25 8
13 7
13 7
13 7
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000
3000 1000

output:

3

result:

ok single line: '3'

Test #13:

score: 0
Accepted
time: 2ms
memory: 3344kb

input:

4 2
10 10
10 10
10 10
9 2

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 66ms
memory: 7040kb

input:

110000 60000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 100000
222200000 10000...

output:

99999

result:

ok single line: '99999'

Test #15:

score: -100
Time Limit Exceeded

input:

200000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
10000...

output:


result: