Submission #972419

# Submission time Handle Problem Language Result Execution time Memory
972419 2024-04-30T11:52:35 Z vjudge1 Art Exhibition (JOI18_art) C++17
0 / 100
1 ms 456 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define pon ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  int T=1;
#define ponchik signed main
#define pb push_back
#define pf push_front
#define endl "\n"
#define F first
#define S second

const int N=1e5+69,INF=1e18+1488;
void solve() {
	int n;
	vector <pair<int,int>> v;
	cin>>n;
	for (int i=0; i<n; i++)
	{
		int a,b;
		cin>>a>>b;
		v.pb({a,b});
	}
	sort(v.begin(),v.end());
	int sum=v[0].S,ans=0,pos1=0;
	for (int i=1; i<n; i++)
	{
		sum+=v[i].S;
		if (v[i].F-v[pos1].F<=sum) ans+=sum,sum=0,pos1=i;
	}
	int pos2=0;
	sum=0;
	for (int i=1; i<=pos1; i++)
	{
		sum+=v[i-1].S;
		if (v[i].F-v[pos2].F>=sum) ans-=sum,sum=0,pos2=i;
	}
	int mx=ans-v[pos1].F+v[pos2].F;
	for (int i=0; i<n; i++) mx=max(mx,v[i].S);
	cout<<mx;
}
ponchik (/*Alfar ABI*/ ) {
    pon
//  freopen( "###.in" ,"r",stdin); freopen( "###.out" ,"w",stdout);
//	cin>>T;
	while (T--){solve();}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -