QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370451 | #4233. Reset | InfinityNS | WA | 0ms | 3916kb | C++20 | 1.8kb | 2024-03-29 08:03:37 | 2024-03-29 08:03:38 |
Judging History
answer
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
const int mod=998244353;
inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;}
inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;}
inline int mul(int x,int y){return ((ll)x*y)%mod;}
inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;}
inline int invv(int x){return step(x,mod-2);}
const int maxn=2e5+10;
ll c,n,t[maxn],d[maxn];
using int128=__int128_t;
int cnt[maxn];
typedef pair<ll,ll> pll;
vector<pair<pii,int>>cand;
bool check(ll mid){
for(int i=1;i<=n;i++)cnt[i]=0;
ll total=min(((int128)mid+1)*min(n,c),(int128)1e18);
ll sum=0;
ll cpc=c;
int i=-1;
while(++i<cand.size() && total>0){
int x=cand[i].ss;
ll d=min(min(total,(ll)cand[i].ff.ss), (ll)mid+1-cnt[x] );
cnt[x]+=d;
total-=d;
sum+=(cand[i].ff.ss-d)*(ll)cand[i].ff.ff;
}
if(total<min(n,c))cpc-=min(n,c)-total;
return sum<=cpc;
}
int main(){
///freopen("test.txt","r",stdin);
scanf("%lld %lld",&n,&c);
for(int i=1;i<=n;i++){
scanf("%lld %lld",&t[i],&d[i]);
cand.pb({{d[i],t[i]/d[i]},i});
if(t[i]%d[i])cand.pb({{t[i]%d[i],1},i});
}
sort(cand.begin(),cand.end());
reverse(cand.begin(),cand.end());
//check(249);
//return 0;
ll l=0;
ll r=2e15;
ll sr,ret=0;
while(l<=r){
sr=(l+r)/2;
if(check(sr)){
r=sr-1;
ret=sr;
}
else l=sr+1;
}
printf("%lld\n",ret);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3916kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
3 2345 333 1 444 2 555 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
1 500 1000 2
output:
250
result:
ok single line: '250'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3908kb
input:
3 2345 3333 5 4444 6 5555 6
output:
645
result:
wrong answer 1st lines differ - expected: '646', found: '645'