Submission #1106035

#TimeUsernameProblemLanguageResultExecution timeMemory
1106035huyngodzzFuel Station (NOI20_fuelstation)C++14
100 / 100
376 ms68488 KiB
///huynhocute123/// #include<bits/stdc++.h> using namespace std; #define S second #define F first #define pii pair<int,int> #define piii pair<int,pair<int,int>> #define pb push_back #define FOR(i, a, b) for(int i = a; i <= b; ++i) #define REP(i, a, b) for(int i = b; i >= a; --i) #define ALL(v) v.begin(),v.end() #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin); #define out(name) if(fopen(name, "w")) freopen(name, "w", stdout); //random_device rd; //mt19937 rng(rd()); //#pragma GCC optimize ("O3") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("popcnt") #define int long long const int maxN = 1e6 + 9 ; const int modd = 1e9 + 7; const int base = 2309; const int MAX = 1e9+9; const double pi = 3.14159265358979323846; const double rad = 3.14159265358979323846 /180; void minimize(int &u, int v){ if(v < u) u = v; } void maximize(int &u, int v){ if(v > u) u = v; } int n, k, t, m, res, a[maxN], d, lazy[4 *maxN], st[4 *maxN]; int l, r; bool vis[maxN]; vector<int> e[maxN]; struct node{ int x, di , mn; }fuel[maxN]; bool cmp(node a , node b){ return a.x < b.x; } void push(int id ){ if(lazy[id] == 0 )return; st[id*2] +=lazy[id]; st[id * 2 +1] += lazy[id]; lazy[id * 2] += lazy[id]; lazy[id*2 +1 ] +=lazy[id]; lazy[id] =0; } void upd(int id ,int l ,int r ,int u ,int v, int val){ if(v < l || u > r)return; if(u <= l && r <= v){ st[id]+= val; lazy[id] +=val; return; } int mid = (l + r)/2; push(id); upd(id*2 ,l ,mid ,u ,v, val); upd(id*2 + 1 ,mid + 1, r ,u ,v, val); st[id] = max(st[id*2] ,st[id*2 +1]); } int get(int id ,int l ,int r ,int u ,int v){ if(v < l || u > r)return - MAX; if(u <= l && r<= v)return st[id]; int mid =( l + r ) /2; push(id); return max(get(id*2 , l ,mid ,u ,v) , get(id*2 + 1, mid +1 ,r ,u , v) ); } bool cmpp(pii a ,pii b){ if(a.F != b.F)return a.F > b.F; return a.S > b.S; } void solve(){ cin >> n >> d; for(int i= 1;i <= n ;i++){ cin >> fuel[i].x >>fuel[i].di >> fuel[i].mn; } sort(fuel +1 , fuel +1 + n , cmp); vector<pii> ed; for(int i =1;i <= n ;i++){ upd(1, 1, n , i , i ,fuel[i].x); ed.pb({fuel[i].mn , i}); } sort(ALL(ed), cmpp); res = d; long long tot = 0; for(auto [x,y] : ed){ tot += fuel[y].di; upd(1, 1 ,n , y + 1, n , -fuel[y].di); long long tmp = max(st[1] , d -tot); tmp = max(tmp , 0LL); if(tmp <= x){ minimize(res, tmp); } } cout << res; } signed main(){ // freopen("name.inp","r",stdin); // freopen("name.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(0); inp("task.inp"); t = 1; // cin >> t; while( t-- )solve(); cerr << '\n' << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s\n" ; }

Compilation message (stderr)

FuelStation.cpp: In function 'void solve()':
FuelStation.cpp:89:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   89 |     for(auto [x,y] : ed){
      |              ^
FuelStation.cpp: In function 'int main()':
FuelStation.cpp:12:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~
FuelStation.cpp:108:5: note: in expansion of macro 'inp'
  108 |     inp("task.inp");
      |     ^~~
#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...