QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#350619 | #4233. Reset | LaStataleBlue | WA | 1ms | 3776kb | C++23 | 2.2kb | 2024-03-10 21:36:44 | 2024-03-10 21:36:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
void solve(){
long long n,c;
cin>>n>>c;
multiset<array<long long,3>> opz; //passo,num,residuo
multiset<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(opz.find(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(ans>0){
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: 3776kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
3 2345 333 1 444 2 555 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
1 500 1000 2
output:
250
result:
ok single line: '250'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3476kb
input:
3 2345 3333 5 4444 6 5555 6
output:
646
result:
ok single line: '646'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3532kb
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: 3584kb
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'