Submission #1033812

# Submission time Handle Problem Language Result Execution time Memory
1033812 2024-07-25T06:41:22 Z vjudge1 Art Exhibition (JOI18_art) C++17
0 / 100
2 ms 344 KB
#include<bits/stdc++.h>
#define ll long long
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sp << " "
#define task "tl"
using namespace std;
pair<ll,ll> a[500005];
ll mcd[500005];
ll n;

void sub123(){
	sort(a+1,a+n+1);
	for(ll i = 1; i <= n; i++) mcd[i]=mcd[i-1]+a[i].second;
	ll ma = -1e18;
	for(ll i = 1; i <= n; i++){
		for(ll j = i; j <= n; j++){
			ma = max(ma, (mcd[j]-a[j].first)-(mcd[i-1]-a[i].first));
		}
	}
	cout << ma;
}

void sub4(){
	sort(a+1,a+n+1);
	for(ll i = 1; i <= n; i++) mcd[i]=mcd[i-1]+a[i].second;
	ll ma = -1e18, mi = 1e18;
	for(ll i = 1; i <= n; i++){
		mi = min(mi, mcd[i-1]-a[i].first);
		ma = max(ma, mcd[i]-a[i].first-mi);
	}
	cout << ma;
}
int main(){
	faster;
	freopen(task".inp","r",stdin);
	freopen(task".out","w",stdout);
	cin >> n;
	for(ll i = 1; i <= n; i++){
		cin >> a[i].first >> a[i].second;
	}
	if(n<=5000){
		sub123();
	}
	else{
		sub4();
	}
	return 0;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:35:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  freopen(task".inp","r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
art.cpp:36:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  freopen(task".out","w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -