Submission #1113792

#TimeUsernameProblemLanguageResultExecution timeMemory
1113792AvianshFuel Station (NOI20_fuelstation)C++17
24 / 100
3058 ms14536 KiB
#include <bits/stdc++.h> using namespace std; int n,d; bool check(array<int,3>fuels[], int f){ int F=f; //cout << "attempting: " << f << "\n"; for(int 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<int,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<int>bs; for(int i = 1;i<=n;i++){ int 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); int hi = d; for(int i : bs){ if(check(fuels,i)){ hi=i; break; } } int lo = 0; while(lo<hi){ int mid = (lo+hi)/2; if(check(fuels,mid)){ hi=mid; } else{ lo=mid+1; } } cout << lo; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...