Submission #95426

#TimeUsernameProblemLanguageResultExecution timeMemory
95426choikiwonDivide and conquer (IZhO14_divide)C++17
100 / 100
59 ms10196 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MN = 100010; int N; int X[MN], G[MN], E[MN]; ll esum[MN], gsum[MN]; vector<pair<ll, int> > ord1, ord2; priority_queue<int> pq; int main() { scanf("%d", &N); for(int i = 0; i < N; i++) { scanf("%d %d %d", &X[i], &G[i], &E[i]); } for(int i = 0; i < N; i++) { esum[i] = E[i]; gsum[i] = G[i]; if(i) { esum[i] += esum[i - 1]; gsum[i] += gsum[i - 1]; } } for(int i = 0; i < N; i++) { ord1.push_back({ (i? esum[i - 1] : 0) - X[i], i }); ord2.push_back({ esum[i] - X[i], i }); } sort(ord1.begin(), ord1.end()); sort(ord2.begin(), ord2.end()); int pos = (int)ord2.size() - 1; ll ans = 0; for(int i = (int)ord1.size() - 1; i >= 0; i--) { while(pos >= 0 && ord2[pos].first >= ord1[i].first) { pq.push(ord2[pos--].second); } int x = ord1[i].second; if(!pq.empty() && pq.top() >= x) { ans = max(ans, gsum[ pq.top() ] - (x? gsum[x - 1] : 0)); } } printf("%lld", ans); }

Compilation message (stderr)

divide.cpp: In function 'int main()':
divide.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
divide.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &X[i], &G[i], &E[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...