QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#353225 | #4233. Reset | PetroTarnavskyi | WA | 0ms | 3848kb | C++20 | 1.4kb | 2024-03-13 23:36:50 | 2024-03-13 23:36:51 |
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, vector<PII> a)
{
int w = min(n, c);
__int128 time = (__int128)w * m;;
vector<tuple<int, int, int>> v;
FOR (i, 0, n)
{
auto& [d, t] = a[i];
int cnt = t / d;
if (m < cnt)
cnt = m;
if (time < cnt)
cnt = time;
t -= cnt * d;
time -= cnt;
d = min(d, t);
v.PB({d, t, cnt});
}
sort(ALL(v), greater());
LL last = 0;
FOR (i, 0, n)
{
auto [d, t, cnt] = v[i];
if (t == 0)
continue;
if (cnt != m && time != 0)
{
time--;
t -= d;
last += t;
}
else
{
last += max(0, t - d) + 1;
}
}
return last <= c;
}
const int INF = 1e9 + 47;
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].S >> a[i].F;
sort(ALL(a), greater());
LL l = -1, r = (LL)n * INF;
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: 0ms
memory: 3620kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3816kb
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: 3556kb
input:
3 2345 333 1 444 2 555 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
1 500 1000 2
output:
250
result:
ok single line: '250'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
3 2345 3333 5 4444 6 5555 6
output:
646
result:
ok single line: '646'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3564kb
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: -100
Wrong Answer
time: 0ms
memory: 3620kb
input:
8 6 40 10 40 10 40 10 40 10 40 10 20 5 7 3 5 3
output:
5
result:
wrong answer 1st lines differ - expected: '4', found: '5'