Submission #465911

#TimeUsernameProblemLanguageResultExecution timeMemory
465911dattranxxxArt Exhibition (JOI18_art)C++11
100 / 100
260 ms24812 KiB
/*
 * Author :  shora
 */
#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cerr << _ << ' ';} cerr << endl;
using namespace std;
using ll = long long;
const ll oo = 1e18;
const int N = 5e5;
struct P {
	int v = 0;
	ll w = 0, f = 0;
	bool operator < (const P& p) {
		return w < p.w;
	}
};
P a[N+1];
int n;
int main() {
  cin.tie(0)->sync_with_stdio(0); cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i)
  	cin >> a[i].w >> a[i].v;
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i)
		a[i].f = a[i-1].f + a[i].v;
	ll res = -oo, mx = -oo; 
	// a[r].f - a[l-1].f - a[r].w + a[l].w
	// a[r].f - a[r].w + (a[l].w - a[l-1].f)
	for (int r = 1; r <= n; ++r) {
		mx = max(mx, a[r].w - a[r-1].f);
		res = max(res, a[r].f - a[r].w + mx);
	}
	cout << res;
  return 0;
}

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:22:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   22 |   for (int i = 1; i <= n; ++i)
      |   ^~~
art.cpp:24:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   24 |  sort(a + 1, a + n + 1);
      |  ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...