Submission #171708

# Submission time Handle Problem Language Result Execution time Memory
171708 2019-12-30T07:03:17 Z dennisstar Art Exhibition (JOI18_art) C++11
0 / 100
7 ms 4600 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
#define all(V) ((V).begin()), ((V).end())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<int> vim;
typedef vector<ll> vlm;

int N;
pll ar[500010];
ll B[500010], C[500010];
ll seg[(1<<20)];
ll x, y;

ll mx(int fr, int re) {
	fr+=(1<<19); re+=(1<<19);
	ll ret=seg[(1<<19)];
	while (fr<=re) {
		if (fr%2) ret=max(ret, seg[fr++]);
		if (re%2==0) ret=max(ret, seg[re--]);
		fr/=2; re/=2;
	}
	return ret;
}

int main() {
	scanf("%d", &N);
	for (int i=0; i<N; i++) {
		scanf("%lld %lld", &x, &y);
		ar[i]={x, y};
	}
	sort(ar, ar+N);
	for (int i=0; i<N; i++) B[i]=ar[i].se, C[i]=ar[i].fi+ar[i].se-ar[i+1].fi;
	for (int i=N-1; i>=0; i--) seg[i+(1<<19)]=seg[i+1+(1<<19)]+C[i];
	for (int i=(1<<19)-1; i; i--) seg[i]=max(seg[i*2], seg[i*2+1]);
	ll ans=B[0], s=0;
	for (int i=N-1; i; i--) {
		s+=C[i];
		ans=max(ans, mx(0, i-1)-s+B[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
art.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4600 KB Output isn't correct
2 Halted 0 ms 0 KB -