Submission #737447

# Submission time Handle Problem Language Result Execution time Memory
737447 2023-05-07T08:02:50 Z josanneo22 Art Exhibition (JOI18_art) C++17
100 / 100
93 ms 14892 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
int n; 
vector<pii> a;
vector<int> val;
int get(int x,int y){
	return val[y+1]-val[x];
}
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int rd()
{
	int s=0;
	char ch=getchar(),last;
	while(ch<'0'||ch>'9') last=ch,ch=getchar();
	while(ch>='0'&&ch<='9') s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
	return last=='-'?-s:s;
}
int num[100];
inline void rt(int x)
{
	if(x<0) putchar('-'),x=-x;;
	int len=0;
	do num[len++]=x%10;while(x/=10);
	while(len--) putchar(num[len]+'0');
}
void solve(){
	n=rd();
	a.resize(n);val.resize(n+2);
	for(auto&x:a) x.first=rd(),x.second=rd(); 
	sort(a.begin(),a.end());
	for(int i=1;i<=n;i++) val[i]=val[i-1]+a[i-1].second;
	int mx=0,ans=0;
	for(int i=0;i<n;i++){
		mx=max(mx,a[i].first-get(0,i-1));
		ans=max(ans,get(0,i)-a[i].first+mx);
	}
	rt(ans);
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	solve();
}

Compilation message

art.cpp: In function 'long long int rd()':
art.cpp:23:18: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   23 |  return last=='-'?-s:s;
      |         ~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 1 ms 580 KB Output is correct
32 Correct 1 ms 580 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 1 ms 580 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 584 KB Output is correct
41 Correct 1 ms 572 KB Output is correct
42 Correct 2 ms 584 KB Output is correct
43 Correct 2 ms 580 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 1 ms 596 KB Output is correct
46 Correct 1 ms 596 KB Output is correct
47 Correct 1 ms 596 KB Output is correct
48 Correct 1 ms 596 KB Output is correct
49 Correct 1 ms 596 KB Output is correct
50 Correct 1 ms 596 KB Output is correct
51 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 1 ms 580 KB Output is correct
32 Correct 1 ms 580 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 1 ms 580 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 584 KB Output is correct
41 Correct 1 ms 572 KB Output is correct
42 Correct 2 ms 584 KB Output is correct
43 Correct 2 ms 580 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 1 ms 596 KB Output is correct
46 Correct 1 ms 596 KB Output is correct
47 Correct 1 ms 596 KB Output is correct
48 Correct 1 ms 596 KB Output is correct
49 Correct 1 ms 596 KB Output is correct
50 Correct 1 ms 596 KB Output is correct
51 Correct 1 ms 596 KB Output is correct
52 Correct 71 ms 14412 KB Output is correct
53 Correct 72 ms 14868 KB Output is correct
54 Correct 72 ms 14888 KB Output is correct
55 Correct 78 ms 14776 KB Output is correct
56 Correct 93 ms 14892 KB Output is correct
57 Correct 73 ms 14884 KB Output is correct
58 Correct 71 ms 14796 KB Output is correct
59 Correct 70 ms 14824 KB Output is correct
60 Correct 70 ms 14884 KB Output is correct
61 Correct 76 ms 14884 KB Output is correct
62 Correct 81 ms 14892 KB Output is correct
63 Correct 76 ms 14792 KB Output is correct
64 Correct 72 ms 14888 KB Output is correct
65 Correct 69 ms 14884 KB Output is correct
66 Correct 69 ms 14796 KB Output is correct
67 Correct 74 ms 14892 KB Output is correct
68 Correct 78 ms 14792 KB Output is correct