Submission #1256736

#TimeUsernameProblemLanguageResultExecution timeMemory
1256736XXBabaProBerkayArt Exhibition (JOI18_art)C++20
50 / 100
1093 ms12108 KiB
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define MP make_pair
#define PB push_back

using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using vec = vector<T>;

template<typename T, int N>
using arr = array<T, N>;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

const int INF = 1e9 + 7;
const int MOD = 998244353;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int N;
	cin >> N;
	vec<pair<ll, ll>> A(N + 1);
	for (int i = 1; i <= N; i++)
		cin >> A[i].F >> A[i].S;

	sort(A.begin() + 1, A.end());

	vec<ll> p(N + 1);
	ll ans = 0;
	for (int i = 1; i <= N; i++)
	{
		p[i] = p[i - 1] + A[i].S;
		for (int j = 0; j < i; j++)
			ans = max(ans, p[i] - p[j] - (A[i].F - A[j + 1].F));
	}

	cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...