QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#602204 | #9427. Collect the Coins | ucup-team3282 | RE | 0ms | 0kb | C++14 | 1.2kb | 2024-09-30 20:59:50 | 2024-09-30 20:59:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
int T;
int n;
int t[maxn],c[maxn];
bool f(int i,int j,int v){
if(j>=i)
return 1;
return (ll)v*(t[i]-t[j])>=abs(c[i]-c[j]);
}
bool check(int v){
vector<int> il,ir;
for(int i=2;i<=n;i++){
if(!f(i,i-1,v)){
if(c[i]>c[i-1]){
il.push_back(i-1);
ir.push_back(i);
}
else{
il.push_back(i);
ir.push_back(i-1);
}
}
}
// cout<<"v: "<<v<<endl;for(int i:il)cout<<i<<endl;cout<<endl;for(int i:ir)cout<<i<<endl;cout<<endl;
il.resize(unique(il.begin(),il.end())-il.begin());
ir.resize(unique(ir.begin(),ir.end())-ir.begin());
int pl=0,pr=0;
for(int i=1;i<=n;i++){
if(pl+2<il.size()&&il[pl+1]<=i)
pl++;
if(pr+2<ir.size()&&ir[pr+1]<=i)
pr++;
if(!( (f(i,il[pl],v)&&f(il[pl+1],i,v)) || (f(i,ir[pr],v)&&f(ir[pr+1],i,v)) ))
return 0;
}
return 1;
}
int main(){
ios::sync_with_stdio(0);
cin>>T;
while(T--){
cin>>n;
for(int i=1;i<=n;i++)
cin>>t[i]>>c[i];
int l=0,r=1e9,mid,ans=-1;
while(l<=r){
mid=(l+r)>>1;
if(check(mid)){
ans=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
cout<<ans<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 5 1 1 3 7 3 4 4 3 5 10 1 10 100 3 10 100 10 1000 10 10000
output:
500000000