QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#370448 | #4233. Reset | InfinityNS | TL | 2340ms | 19380kb | C++20 | 1.9kb | 2024-03-29 07:55:58 | 2024-03-29 07:55:58 |
Judging History
answer
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
const int mod=998244353;
inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;}
inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;}
inline int mul(int x,int y){return ((ll)x*y)%mod;}
inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;}
inline int invv(int x){return step(x,mod-2);}
const int maxn=2e5+10;
ll c,n,t[maxn],d[maxn];
using int128=__int128_t;
typedef pair<ll,ll> pll;
bool check(ll mid){
ll total=min(((int128)mid+1)*min(n,c),(int128)1e18);
multiset<pair<pii,int>>st;
for(int i=1;i<=n;i++){
st.insert({ {d[i],t[i]},0 });
}
ll sum=0;
ll cpc=c;
while(st.size() && total>0){
pair<pii,int>x=(*st.rbegin());
st.erase(st.find(x));
ll d=min(min(total,(ll)x.ff.ss/x.ff.ff), (ll)mid+1-x.ss );
x.ss+=d;
x.ff.ss-=d*x.ff.ff;
total-=d;
x.ff.ff=min(x.ff.ff,x.ff.ss);
if(x.ss==mid+1 || x.ff.ss==0){
sum+=x.ff.ss;
continue;
}
st.insert(x);
}
if(total<min(n,c))cpc-=min(n,c)-total;
while(st.size()){
sum+=(*st.begin()).ff.ss;
st.erase(st.begin());
}
return sum<=cpc;
}
int main(){
///freopen("test.txt","r",stdin);
scanf("%lld %lld",&n,&c);
for(int i=1;i<=n;i++){
scanf("%lld %lld",&t[i],&d[i]);
}
//check(249);
//return 0;
ll l=0;
ll r=2e15;
ll sr,ret=0;
while(l<=r){
sr=(l+r)/2;
if(check(sr)){
r=sr-1;
ret=sr;
}
else l=sr+1;
}
printf("%lld\n",ret);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3828kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
3 2345 333 1 444 2 555 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 4068kb
input:
1 500 1000 2
output:
250
result:
ok single line: '250'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
3 2345 3333 5 4444 6 5555 6
output:
646
result:
ok single line: '646'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3844kb
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: 0ms
memory: 4012kb
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: 0
Accepted
time: 1ms
memory: 4072kb
input:
5 4 29 8 30 7 2000 1000 2000 1000 2000 1000
output:
3
result:
ok single line: '3'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3780kb
input:
27 19 21 5 14 5 14 5 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000
output:
4
result:
ok single line: '4'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3824kb
input:
24 21 25 8 13 7 13 7 13 7 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000 3000 1000
output:
3
result:
ok single line: '3'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
4 2 10 10 10 10 10 10 9 2
output:
3
result:
ok single line: '3'
Test #14:
score: 0
Accepted
time: 1215ms
memory: 12408kb
input:
110000 60000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 100000 222200000 10000...
output:
99999
result:
ok single line: '99999'
Test #15:
score: 0
Accepted
time: 2340ms
memory: 19380kb
input:
200000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 10000...
output:
199999999999999
result:
ok single line: '199999999999999'
Test #16:
score: -100
Time Limit Exceeded
input:
200000 7 966486041 28 936158040 29 991239679 47 988279269 31 905558493 68 998009820 40 901181342 66 925252807 10 995161072 3 947576761 21 980670741 66 931584704 3 944714227 42 992178536 6 905079737 39 982672468 87 963094272 21 919244645 48 935633595 3 903091417 4 923453539 72 916293313 82 981382022 ...
output:
1405907290168