QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#353115 | #4233. Reset | PetroTarnavskyi# | WA | 1ms | 3836kb | C++20 | 1.2kb | 2024-03-13 21:23:44 | 2024-03-13 21:23:44 |
Judging History
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;
timeLast += max(0LL, t - (m + 1) * 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: 3824kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3548kb
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: 3492kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
3 2345 3333 5 4444 6 5555 6
output:
646
result:
ok single line: '646'
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 3552kb
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'