Submission #1013149

#TimeUsernameProblemLanguageResultExecution timeMemory
1013149TrinhKhanhDungFuel Station (NOI20_fuelstation)C++14
0 / 100
96 ms9040 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define sz(x) (int)x.size() #define ALL(v) v.begin(),v.end() #define MASK(k) (1LL << (k)) #define BIT(x, i) (((x) >> (i)) & 1) #define oo (ll)1e18 #define INF (ll)1e9 #define MOD (ll)(998244353) using namespace std; template<class T1, class T2> bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;} template<class T1, class T2> bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;} template<class T1, class T2> void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;} template<class T1, class T2> void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;} template<class T> void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());} const int MAX = 5e5 + 10; int N, D; tuple<int, int, int> a[MAX]; bool OK(int x){ ll cur = x; for(int i=1; i<=N+1; i++){ cur -= (get<0>(a[i]) - get<0>(a[i - 1])); if(cur < 0) return false; if(x <= get<2>(a[i])) maximize(cur, get<1>(a[i])); } return true; } void solve(){ cin >> N >> D; for(int i=1; i<=N; i++){ cin >> get<0>(a[i]) >> get<1>(a[i]) >> get<2>(a[i]); } sort(a + 1, a + N + 1); a[N + 1] = make_tuple(D, 0, 0); int l = 1, r = D; while(l < r){ int m = (l + r) >> 1; if(OK(m)){ r = m; } else{ l = m + 1; } } cout << r << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("split.inp", "r", stdin); // freopen("split.out", "w", stdout); int tt = 1; // cin >> tt; while(tt--){ solve(); } 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...