QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#370440 | #4233. Reset | InfinityNS | WA | 1ms | 3788kb | C++20 | 2.1kb | 2024-03-29 07:43:38 | 2024-03-29 07:43:39 |
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){
int128 total=min(((int128)mid+1)*min(n,c),(int128)1e18);
multiset<pair<pll,ll>>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<pll,ll>x=(*st.rbegin());
st.erase(st.find(x));
int128 d=min(min(total,(int128)x.ff.ss/x.ff.ff), (int128)mid+1-x.ss );
///printf("%lld %lld %lld\n",d,x.ff.ff,x.ff.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;
///printf("%lld CPC\n",cpc);
///if(x.ss==mid+1)cpc--;
continue;
}
st.insert(x);
}
cpc-=c-total%min(n,c);
while(st.size()){
sum+=(*st.begin()).ff.ss;
st.erase(st.begin());
}
///printf("%lld %lld | %lld AA\n",sum,cpc,mid);
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=3e15;
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: 3788kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3768kb
input:
2 1345 1344 1 10 10
output:
1343
result:
wrong answer 1st lines differ - expected: '0', found: '1343'