QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#350616 | #4233. Reset | LaStataleBlue | WA | 1ms | 3624kb | C++23 | 2.1kb | 2024-03-10 21:29:51 | 2024-03-10 21:29:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
void solve(){
long long n,c;
cin>>n>>c;
set<array<long long,3>> opz; //passo,num,residuo
set<array<long long,3>> curr; //tempo di fine,passo,residuo
long long sum=0;
for(int i=0;i<n;i++){
long long t,d;
cin>>t>>d;
sum+=t;
opz.insert({d,t/d,t%d});
}
long long ans=0,currt=0,currpasso=0;
auto updcurr = [&](){
while((int)curr.size()<c && opz.size()>0){
auto x = *opz.rbegin();
opz.erase(x);
currpasso+=x[0];
swap(x[0],x[1]);
x[0]+=currt;
//cout<<"aggiungo "<<x[0]<<" "<<x[1]<<" "<<x[2]<<"\n";
curr.insert(x);
}
};
auto delcurr = [&](){
while(!curr.empty() && (*curr.begin())[0]==currt){
if((*curr.begin())[2]!=0){
opz.insert({(*curr.begin())[2],1,0});
}
currpasso-=(*curr.begin())[1];
curr.erase(curr.begin());
}
};
updcurr();
while(sum>c){
long long succt=(*curr.begin())[0];
long long tmp = min(succt-currt,(sum-c+currpasso-1)/currpasso);
//cout<<"passa "<<tmp<<" secondi\n";
ans+=tmp;
currt+=tmp;
sum-=tmp*currpasso;
if(sum<=c){
assert(tmp>=1);
break;
}
delcurr();
updcurr();
}
vector<long long> v;
for(auto i : curr)v.push_back(i[1]);
long long rim = c-v.size();
if(rim>=sum)ans--;
else{
sort(v.begin(),v.end());
for(int i=0;i<(int)v.size();i++){
rim++;
sum+=v[i];
if(rim>=sum){
ans--;
break;
}
}
}
cout<<ans<<"\n";
}
int main(){
//ios::sync_with_stdio(false);
//cin.tie(0);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3580kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3596kb
input:
3 2345 333 1 444 2 555 3
output:
-1
result:
wrong answer 1st lines differ - expected: '0', found: '-1'