#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
struct art{
ll height;
ll beauty;
void read(){
cin>>height>>beauty;
}
};
bool operator<(art&a, art&b){
return a.height<b.height;
}
signed main(){
int n;cin>>n;
vector<art> arts(n);
int pref[n];
for(int i=0;i<n;i++){
arts[i].read();
}
sort(arts.begin(),arts.end());
int actSum=0;
for(int i = 0;i<n;i++){
actSum+=arts[i].beauty;
pref[i]=actSum;
}
int partialSum[n];
for(int i=0;i<n;i++){
partialSum[i] = pref[i]-arts[i].height;
}
int maxi = partialSum[n-1];
int maxiSuf[n];
for(int i=n-1;i>=0;i--){
maxi=max(maxi,partialSum[i]);
maxiSuf[i] = maxi;
}
ll ans=0;
for(int iDeb=0;iDeb<n;iDeb++){
int toErase = 0;
if(iDeb>0)toErase=pref[iDeb-1];
ans = max(ans,maxiSuf[iDeb]+arts[iDeb].height-toErase);
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
4 ms |
704 KB |
Output is correct |
28 |
Correct |
4 ms |
600 KB |
Output is correct |
29 |
Correct |
4 ms |
604 KB |
Output is correct |
30 |
Correct |
4 ms |
600 KB |
Output is correct |
31 |
Correct |
6 ms |
856 KB |
Output is correct |
32 |
Correct |
4 ms |
672 KB |
Output is correct |
33 |
Correct |
4 ms |
604 KB |
Output is correct |
34 |
Correct |
4 ms |
604 KB |
Output is correct |
35 |
Correct |
4 ms |
700 KB |
Output is correct |
36 |
Correct |
4 ms |
604 KB |
Output is correct |
37 |
Correct |
4 ms |
604 KB |
Output is correct |
38 |
Correct |
4 ms |
604 KB |
Output is correct |
39 |
Correct |
4 ms |
700 KB |
Output is correct |
40 |
Correct |
4 ms |
676 KB |
Output is correct |
41 |
Correct |
4 ms |
704 KB |
Output is correct |
42 |
Correct |
4 ms |
604 KB |
Output is correct |
43 |
Correct |
4 ms |
604 KB |
Output is correct |
44 |
Correct |
4 ms |
604 KB |
Output is correct |
45 |
Correct |
6 ms |
604 KB |
Output is correct |
46 |
Correct |
4 ms |
656 KB |
Output is correct |
47 |
Correct |
4 ms |
600 KB |
Output is correct |
48 |
Correct |
4 ms |
604 KB |
Output is correct |
49 |
Correct |
4 ms |
604 KB |
Output is correct |
50 |
Correct |
4 ms |
604 KB |
Output is correct |
51 |
Correct |
4 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
4 ms |
704 KB |
Output is correct |
28 |
Correct |
4 ms |
600 KB |
Output is correct |
29 |
Correct |
4 ms |
604 KB |
Output is correct |
30 |
Correct |
4 ms |
600 KB |
Output is correct |
31 |
Correct |
6 ms |
856 KB |
Output is correct |
32 |
Correct |
4 ms |
672 KB |
Output is correct |
33 |
Correct |
4 ms |
604 KB |
Output is correct |
34 |
Correct |
4 ms |
604 KB |
Output is correct |
35 |
Correct |
4 ms |
700 KB |
Output is correct |
36 |
Correct |
4 ms |
604 KB |
Output is correct |
37 |
Correct |
4 ms |
604 KB |
Output is correct |
38 |
Correct |
4 ms |
604 KB |
Output is correct |
39 |
Correct |
4 ms |
700 KB |
Output is correct |
40 |
Correct |
4 ms |
676 KB |
Output is correct |
41 |
Correct |
4 ms |
704 KB |
Output is correct |
42 |
Correct |
4 ms |
604 KB |
Output is correct |
43 |
Correct |
4 ms |
604 KB |
Output is correct |
44 |
Correct |
4 ms |
604 KB |
Output is correct |
45 |
Correct |
6 ms |
604 KB |
Output is correct |
46 |
Correct |
4 ms |
656 KB |
Output is correct |
47 |
Correct |
4 ms |
600 KB |
Output is correct |
48 |
Correct |
4 ms |
604 KB |
Output is correct |
49 |
Correct |
4 ms |
604 KB |
Output is correct |
50 |
Correct |
4 ms |
604 KB |
Output is correct |
51 |
Correct |
4 ms |
604 KB |
Output is correct |
52 |
Correct |
402 ms |
31344 KB |
Output is correct |
53 |
Correct |
399 ms |
32616 KB |
Output is correct |
54 |
Correct |
376 ms |
32592 KB |
Output is correct |
55 |
Correct |
391 ms |
32492 KB |
Output is correct |
56 |
Correct |
372 ms |
32592 KB |
Output is correct |
57 |
Correct |
385 ms |
32488 KB |
Output is correct |
58 |
Correct |
384 ms |
32592 KB |
Output is correct |
59 |
Correct |
387 ms |
32500 KB |
Output is correct |
60 |
Correct |
378 ms |
32480 KB |
Output is correct |
61 |
Correct |
382 ms |
32448 KB |
Output is correct |
62 |
Correct |
382 ms |
32592 KB |
Output is correct |
63 |
Correct |
391 ms |
32720 KB |
Output is correct |
64 |
Correct |
380 ms |
32496 KB |
Output is correct |
65 |
Correct |
385 ms |
32504 KB |
Output is correct |
66 |
Correct |
381 ms |
32496 KB |
Output is correct |
67 |
Correct |
385 ms |
32844 KB |
Output is correct |
68 |
Correct |
397 ms |
32512 KB |
Output is correct |