QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#745296 | #4233. Reset | ngpin04# | WA | 1ms | 3560kb | C++14 | 1.7kb | 2024-11-14 09:01:01 | 2024-11-14 09:01:06 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, c;
cin >> n >> c;
vector<pair<ll, ll>> v(n);
ll total = 0;
for(ll i = 0; i < n; ++i)
cin >> v[i].fi >> v[i].se, total += v[i].fi;
ll l = 1, r = 1e18 + 5, ans = -1;
while(l <= r) {
ll mid = (l + r) / 2;
// cerr << mid << endl;
vector<pair<ll, pair<ll, ll>>> red;
for(auto p : v) {
if(ceil(p.fi / (double)p.se) <= mid) {
red.pb(mp(p.se, mp(p.fi / p.se, 0)));
if(p.fi % p.se != 0) {
if(ceil(p.fi / (double)p.se) == mid) {
red.pb(mp(p.fi % p.se, mp(1, 1)));
}
else {
red.pb(mp(p.fi % p.se, mp(1, 0)));
}
}
}
else {
red.pb(mp(p.se, mp(mid, 0)));
}
}
sort(red.begin(), red.end());
ll lst = 0;
ll rem = 1ll * c * mid;
ll cur = total;
while(red.size() && rem > 0) {
ll init = rem;
cur -= red.back().fi * min((ll)red.back().se.fi, rem);
rem -= min((ll)red.back().se.fi, rem);
red.pop_back();
if(init - rem == mid || red.back().se.se)
++lst;
}
ll rem_time = min((ll)c - lst, rem);
if(cur - rem_time <= 0) {
ans = mid, r = mid - 1;
}
else
l = mid + 1;
}
cout << ans - 1 << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3560kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3556kb
input:
2 1345 1344 1 10 10
output:
123435462203260941
result:
wrong answer 1st lines differ - expected: '0', found: '123435462203260941'