QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65198 | #4233. Reset | Sorting# | WA | 6ms | 11004kb | C++ | 1.4kb | 2022-11-28 01:27:22 | 2022-11-28 01:27:26 |
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];
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;
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*n+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});
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 10324kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 2ms
memory: 9840kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 2ms
memory: 9432kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 2ms
memory: 9796kb
input:
3 2345 333 1 444 2 555 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 2ms
memory: 9816kb
input:
1 500 1000 2
output:
250
result:
ok single line: '250'
Test #6:
score: 0
Accepted
time: 2ms
memory: 11004kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: 0
Accepted
time: 2ms
memory: 10888kb
input:
3 2345 3333 5 4444 6 5555 6
output:
646
result:
ok single line: '646'
Test #8:
score: 0
Accepted
time: 5ms
memory: 9552kb
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: 6ms
memory: 10852kb
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: 0ms
memory: 9980kb
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'