QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#353117#4233. ResetPetroTarnavskyiWA 1ms3836kbC++201.3kb2024-03-13 21:24:382024-03-13 21:24:40

Judging History

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

  • [2024-03-13 21:24:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3836kb
  • [2024-03-13 21:24:38]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;


bool check(int n, LL m, int c, const vector<PII>& a)
{
	multiset<PII> cands;
	
	FOR(i, 0, n)
	{
		cands.insert(MP(-a[i].S, a[i].F));
	}
	
	
	LL time = 0;
	LL timeLast = 0;
	while(SZ(cands))
	{
		auto [d, t] = *cands.begin();
		cands.erase(cands.begin());
	
		d = -d;
		
		int cnt = (t + d - 1) / d;
		
		if(m >= cnt)
		{
			time += cnt;
		}
		else
		{
			time += m;
			
			__int128 ze = 0;
			timeLast += max(ze, (__int128)t - (m + 1) * (__int128)d) + 1;
		}
	}
	
	return time <= (__int128)c * m && timeLast <= c;
}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, c;
	cin >> n >> c;
	vector<PII> a(n);
	FOR(i, 0, n)
		cin >> a[i].F >> a[i].S;
	
	LL l = -1, r = (LL)n * c;
	
	while(r - l > 1)
	{
		LL m = (l + r) / 2;
		if(check(n, m, c, a))
			r = m;
		else
			l = m;
	}
	cout << r << "\n";
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3500kb

input:

3 5
17 5
5 2
15 4

output:

3

result:

ok single line: '3'

Test #2:

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

input:

2 1345
1344 1
10 10

output:

0

result:

ok single line: '0'

Test #3:

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

input:

1 1000000000
1000000000 1

output:

0

result:

ok single line: '0'

Test #4:

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

input:

3 2345
333 1
444 2
555 3

output:

0

result:

ok single line: '0'

Test #5:

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

input:

1 500
1000 2

output:

250

result:

ok single line: '250'

Test #6:

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

input:

1 499
1000 2

output:

250

result:

ok single line: '250'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

3 2345
3333 5
4444 6
5555 6

output:

646

result:

ok single line: '646'

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 3836kb

input:

8 6
40 10
40 10
40 10
40 10
40 10
20 5
4 3
5 3

output:

5

result:

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