Submission #207715

# Submission time Handle Problem Language Result Execution time Memory
207715 2020-03-08T16:48:27 Z Lightning Art Exhibition (JOI18_art) C++17
0 / 100
5 ms 376 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
#define int ll

const int szT = (1 << 19) - 1;
const int INF = 1e9 + 5;

int n, ans;
pll a[szT];
ll t[szT * 4];

void upd(int pos, ll x) {
	pos += szT;
	t[pos] = x;
	while((pos /= 2) >= 1) {
		t[pos] = t[pos * 2] + t[pos * 2 + 1];
	}
}

ll get(int l, int r) {
	ll res = 0;
	for(l += szT, r += szT; l <= r; l /= 2, r /= 2) {
		if(l % 2 == 1) res += t[l++];
		if(r % 2 == 0) res += t[r--];
		if(l > r) break;
	}
	return res;
}


void solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i].F >> a[i].S;
	}
	sort(a + 1, a + n + 1);
	int sum = 0;
	for (int i = 1; i <= n; ++i) {
		sum += a[i].S;
		int cur = sum - (a[i].F - a[1].F);
		ans = max(ans, cur);
		ans = max(ans, cur - get(1, i - 1));
		upd(i, cur);
	}
	cout << ans;
}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt = 1;
	while (tt --) {
		solve();
	}
	return 0;
}
/*
	If you only do what you can do, 
	You will never be more than you are now!
*/

Compilation message

art.cpp:80:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  main () {
        ^
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -