QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65194 | #4233. Reset | Sorting# | WA | 3ms | 5508kb | C++ | 1.3kb | 2022-11-28 00:56:55 | 2022-11-28 00:56:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
int n;
ll c;
set<pair<ll,int> >s,ps;
set<pair<ll,int> >dl;
ll dy=0;
ll t[200001],d[200001];
int main(){
ios::sync_with_stdio(false);cin.tie(0);
cin >> n >> c;
ll ans=0;
ll ct=0;
for(int i=1; i<=n ;i++){
cin >> t[i] >> d[i];
t[i]=t[i]-d[i]+1;
s.insert({d[i],i});
ans+=t[i];
}
if(ans<=c){
cout << "0\n";
return 0;
}
while(s.size()>c){
ps.insert(*s.begin());
s.erase(s.begin());
}
for(auto c:s){
int x=c.se;
dy+=d[x];
dl.insert({ct+t[x]/d[x],x});
}
while(true){
ll nt=dl.begin()->fi;
if(ans-(nt-ct)*dy<=c){
ll res=ct+(ans-c+dy-1)/dy;
cout << res << '\n';
return 0;
}
ans-=(nt-ct)*dy;
ct=nt;
int x=dl.begin()->se;
dl.erase(dl.begin());
if(x<=n){
dy-=d[x];
s.erase({d[x],x});
ps.insert({t[x]%d[x],x+n});
}
else{
x-=n;
s.erase({t[x]%d[x],x+n});
dy-=t[x]%d[x];
}
if(!ps.empty()){
auto it=ps.end();--it;
int x=it->se;ps.erase(it);
if(x<=n){
s.insert({d[x],x});
dl.insert({ct+t[x]/d[x],x});
dy+=d[x];
}
else{
x-=n;
s.insert({t[x]%d[x],x+n});
dl.insert({ct+1,x+n});
dy+=t[x]%d[x];
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3268kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3356kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 3ms
memory: 3332kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 3ms
memory: 5440kb
input:
3 2345 333 1 444 2 555 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 3ms
memory: 3484kb
input:
1 500 1000 2
output:
250
result:
ok single line: '250'
Test #6:
score: 0
Accepted
time: 3ms
memory: 5372kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: 0
Accepted
time: 3ms
memory: 5508kb
input:
3 2345 3333 5 4444 6 5555 6
output:
646
result:
ok single line: '646'
Test #8:
score: 0
Accepted
time: 2ms
memory: 5388kb
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: 0
Accepted
time: 3ms
memory: 3404kb
input:
8 6 40 10 40 10 40 10 40 10 40 10 20 5 7 3 5 3
output:
4
result:
ok single line: '4'
Test #10:
score: -100
Wrong Answer
time: 3ms
memory: 3348kb
input:
5 4 29 8 30 7 2000 1000 2000 1000 2000 1000
output:
4
result:
wrong answer 1st lines differ - expected: '3', found: '4'