답안 #914804

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914804 2024-01-22T17:21:57 Z Nurislam Art Exhibition (JOI18_art) C++14
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long 
///*                                                    __                    __                        __                    */
///*        ======     _      /| /|  __   _            /   |  |   /|  |   @  |    |  |  | /   /| |\  | /   |  |  @ | /        */
///* \-       ||  |_| |_     / |/ | |  | |_  |-        |   |--|  /-|  |   |  \ \  |==|  |-   /=| | \ | |   |--|  | |-         */
///*          ||  | | |_    /     | |__|  _| |_        \__ |  | /  |  |__ |  __|  |  |  | \ /  | |  \| \__ |  |  | | \        */
///* 
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vi> vv;
const int N = 2e6+4, inf = 1e8;

void solve(){
	int n;
	cin >> n;
	vii a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i].ff >> a[i].ss;
	}sort(all(a));
	int pr[n+1]{};
	for(int i = 0; i < n; i++)pr[i+1] = pr[i]+a[i].ss;
	
	int ans = a[0].ss-a[0].ff, l = 0, r = 0;
	while(r < n-1){
		if(pr[r+2] - pr[l] - (a[r+1].ff-a[l].ff) > a[r+1].ss-a[r+1].ff)r++;
		
		else l = r = r+1;
		
		ans = max(ans, pr[r+1] - pr[l] - (a[r].ff - a[l].ff));
	}
	cout << ans << '\n';
}
main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int test = 1;
	//~ cin >> test;
	while(test--){
		solve();
	}
}










Compilation message

art.cpp:40:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   40 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -