Submission #173011

#TimeUsernameProblemLanguageResultExecution timeMemory
173011touristDivide and conquer (IZhO14_divide)C++14
100 / 100
66 ms8228 KiB
#include <iostream> #include <algorithm> #include <vector> using namespace std; #define ll long long #define sz(x) (int)x.size() #define pii pair < int, int > #define pll pair < ll, ll > #define endl "\n" #define METH ios::sync_with_stdio(0); cin.tie(0); #define BEGIN cout << "BEGIN" << endl; #define END cout << "END" << endl; const int N = 1e5 + 9; const int mod = 1e9 + 7; /// ANOTHER HASH MOD: 228228227 const int prime = 29; /// ANOTHER HASH PRIME: 997 const int INF = ((long long) 0xCAFEBABE - 1e9 - 4e8); int n, suf[N]; ll g[N], en[N]; vector < pll > eq; vector < pair < int, pii > > v; inline void read() { scanf("%d", &n); v.push_back({0, {0, 0}}); for (int i = 1; i <= n; i++) { int a, b, c; scanf("%d %d %d", &a, &b, &c); v.push_back({a, {b, c}}); en[i] = en[i - 1] + c; eq.push_back({en[i] - a, i}); g[i] = g[i - 1] + b; } } ll calc(int id) { pll temp = {-(v[id].first - 0LL - en[id - 1]), 0}; int index = lower_bound(eq.begin(), eq.end(), temp) - eq.begin(); return g[suf[index]] - g[id - 1]; } inline void solve() { ll ans = 0; sort(eq.begin(), eq.end()); for (int i = n - 1; i >= 0; i--) { suf[i] = max(suf[i + 1] + 0LL, eq[i].second); } for (int i = 1; i <= n; i++) { ans = max(ans, calc(i)); } cout << ans << endl; } int main() { int t; t = 1; while (t--) { read(); solve(); } }

Compilation message (stderr)

divide.cpp: In function 'void read()':
divide.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
divide.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...