This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
long long n,d;
bool check(array<long long,3>fuels[], long long f){
long long F=f;
//cout << "attempting: " << f << "\n";
for(long long i = 1;i<n+2;i++){
// cout << "at station " << i << "\n";
//cout << fuels[i][0] << " " << fuels[i][1] << " " << fuels[i][2] << "\n";
f-=fuels[i][0]-fuels[i-1][0];
// cout << "current fuel: " << f << "\n";
if(f<0){
return 0;
}
if(F>fuels[i][2]){
continue;
}
f+=fuels[i][1];
//cout << "fueled from station " << i << "\n";
}
return 1;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n>>d;
array<long long,3> fuels[n+2];
fuels[0][0]=0;
fuels[0][1]=0;
fuels[0][2]=d+5;
fuels[n+1][0]=d;
fuels[n+1][1]=0;
fuels[n+1][2]=d+5;
vector<long long>bs;
for(long long i = 1;i<=n;i++){
long long a,b,x;
cin >> x >> a >> b;
fuels[i][0]=x;
fuels[i][1]=a;
fuels[i][2]=b;
bs.push_back(b);
}
bs.push_back(d);
sort(bs.begin(),bs.end());
sort(fuels,fuels+n+2);
if(d<=1e4){
for(int i = 0;i<d;i++){
if(check(fuels,i)){
cout << i;
return 0;
}
}
}
long long hi = d;
for(long long i : bs){
if(check(fuels,i)){
hi=i;
break;
}
}
long long lo = 0;
while(lo<hi){
long long mid = (lo+hi)/2;
if(check(fuels,mid)){
hi=mid;
}
else{
lo=mid+1;
}
}
cout << lo;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |