QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65208 | #4233. Reset | Sorting# | WA | 6ms | 11680kb | C++ | 1.6kb | 2022-11-28 02:21:19 | 2022-11-28 02:21:20 |
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];
vector<pair<ll,ll> >sex[200001];
pair<ll,ll>a[200001];
ll b[200001];
int main(){
ios::sync_with_stdio(false);cin.tie(0);
cin >> n >> c;
if(c<=n){
for(int i=1; i<=n ;i++){
ll t,d;cin >> t >> d;
b[i]=(t+d-1)/d;
}
sort(b+1,b+n+1);
ll ans=b[n];
ll s=0;
for(int i=1; i<=n ;i++) s+=b[i];
ans=max(ans,(s+c-1)/c);
cout << ans-1 << '\n';
return 0;
}
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;
sex[i].push_back({d[i],(t[i]-1)/d[i]});
if((t[i]-1)%d[i]>0) sex[i].push_back({(t[i]-1)%d[i],1});
sex[i].push_back({1,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+=sex[x][0].fi;
dl.insert({ct+sex[x][0].se,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;
int lv=(x-1)/n;
x-=lv*n;
dl.erase(dl.begin());
dy-=sex[x][lv].fi;
s.erase({sex[x][lv].fi,x+lv*n});
if(sex[x].size()>lv+1){
ps.insert({sex[x][lv+1].fi,x+(lv+1)*n});
}
if(!ps.empty()){
auto it=ps.end();--it;
int x=it->se;ps.erase(it);
int lv=(x-1)/n;
x-=lv*n;
dy+=sex[x][lv].fi;
s.insert({sex[x][lv].fi,x+lv*n});
dl.insert({ct+sex[x][lv].se,x+lv*n});
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 11504kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 2ms
memory: 11500kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 2ms
memory: 9464kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 2ms
memory: 11604kb
input:
3 2345 333 1 444 2 555 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 2ms
memory: 11500kb
input:
1 500 1000 2
output:
250
result:
ok single line: '250'
Test #6:
score: 0
Accepted
time: 2ms
memory: 9500kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: 0
Accepted
time: 4ms
memory: 11680kb
input:
3 2345 3333 5 4444 6 5555 6
output:
646
result:
ok single line: '646'
Test #8:
score: 0
Accepted
time: 1ms
memory: 9444kb
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: 1ms
memory: 9540kb
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: 5ms
memory: 9604kb
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'