Submission #66142

# Submission time Handle Problem Language Result Execution time Memory
66142 2018-08-09T21:16:00 Z pamaj Art Exhibition (JOI18_art) C++14
0 / 100
3 ms 376 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
typedef long long ll;

int n;

ll k[maxn], p[maxn];

struct obj
{
	ll val, size;
} it[maxn];

bool compara(obj a, obj b)
{
	if(a.size == b.size) return a.val < b.val;
	return a.size < b.size;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(nullptr);

	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> it[i].size >> it[i].val;
	}

	sort(it + 1, it + n + 1, compara);

	for(int i = 1; i <= n; i++)
	{
		p[i] = it[i].val + p[i - 1]; 
	}

	for(int i = n; i >= 1; i--)
	{
		k[i] = max(k[i + 1], p[i] - it[i].size);
	}


	ll ans = 0;
	for(int i = 1; i <= n; i++)
	{
		ans = max(ans, it[i].size - p[i - 1] + k[i + 1]);
	}


	cout << ans << "\n";


	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -