QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#208228#4233. Resetucup-team1209#WA 273ms9668kbC++201.1kb2023-10-09 11:06:342023-10-09 11:06:34

Judging History

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

  • [2023-10-09 11:06:34]
  • 评测
  • 测评结果:WA
  • 用时:273ms
  • 内存:9668kb
  • [2023-10-09 11:06:34]
  • 提交

answer

#include<bits/stdc++.h>

using std::cin;
using std::cout;
using ll = long long;

const int N = 200005;

int n, c;
struct pr { int val, cnt; };
int t[N], d[N];
ll st;
std::vector<pr> v;
int check(int T) {
	v.clear();
	for(int i = 1;i <= n;++i) {
		int turn = t[i] / d[i];
		if(turn >= T) {
			v.push_back({d[i], T - 1});
			v.push_back({d[i] - 1, 1});
		} else {
			v.push_back({d[i], turn});
			if(turn == T - 1) {
				if(t[i] % d[i])
					v.push_back({t[i] % d[i] - 1, 1});
			} else {
				v.push_back({t[i] % d[i], 1});
			}
		}
	}
	sort(v.begin(), v.end(), [](auto x, auto y) {
		return x.val > y.val;
	});
	ll cnt = (ll) T * c;
	ll sum = 0;
	for(auto x : v) {
		ll sub = std::min<ll>(cnt, x.cnt);
		sum += x.val * sub;
		cnt -= sub;
	}
	return st - sum <= c;
}
int main() {
	cin >> n >> c;
	for(int i = 1;i <= n;++i) {
		cin >> t[i] >> d[i];
		st += t[i];
	}
	int l = 0, r = 1e9 + 1;
	for(;l + 1 < r;) {
		int mid = (l + r) >> 1;
		if(check(mid)) {
			r = mid;
		} else {
			l = mid;
		}
	}
	cout << r - 1 << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3592kb

input:

3 5
17 5
5 2
15 4

output:

3

result:

ok single line: '3'

Test #2:

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

input:

2 1345
1344 1
10 10

output:

0

result:

ok single line: '0'

Test #3:

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

input:

1 1000000000
1000000000 1

output:

0

result:

ok single line: '0'

Test #4:

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

input:

3 2345
333 1
444 2
555 3

output:

0

result:

ok single line: '0'

Test #5:

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

input:

1 500
1000 2

output:

250

result:

ok single line: '250'

Test #6:

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

input:

1 499
1000 2

output:

250

result:

ok single line: '250'

Test #7:

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

input:

3 2345
3333 5
4444 6
5555 6

output:

646

result:

ok single line: '646'

Test #8:

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

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

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

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: 0ms
memory: 3656kb

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: 0ms
memory: 3664kb

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: 0ms
memory: 3660kb

input:

4 2
10 10
10 10
10 10
9 2

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 150ms
memory: 6140kb

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
Wrong Answer
time: 273ms
memory: 9668kb

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:

1000000000

result:

wrong answer 1st lines differ - expected: '199999999999999', found: '1000000000'