#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 100000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t,dp[li][4];
int cev;
string s;
PII p[li];
vector<int> v;
inline int f(int sira,int al){
int cevv=-inf;
if(sira>n){
if(al==0)return -inf;
return 0;
}
if(~dp[sira][al])return dp[sira][al];
if(al==0){
if(sira!=n)
cevv=max(cevv,f(sira+1,1)+p[sira].fi+p[sira].se);
cevv=max(cevv,f(n+1,1)+p[sira].se);
cevv=max(cevv,f(sira+1,0));
}
else{
if(sira!=n)
cevv=max(cevv,f(sira+1,al)+p[sira].se);
cevv=max(cevv,f(n+1,al)+p[sira].se-p[sira].fi);
}
return dp[sira][al]=cevv;
}
main(void){
memset(dp,-1,sizeof(dp));
scanf("%lld",&n);
FOR{
scanf("%lld %lld",&p[i].fi,&p[i].se);
}
sort(p+1,p+n+1);
printf("%lld\n",f(1,0));
return 0;
}
Compilation message
art.cpp:53:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(void){
^
art.cpp: In function 'int main()':
art.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&n);
~~~~~^~~~~~~~~~~
art.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&p[i].fi,&p[i].se);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
15992 KB |
Output is correct |
2 |
Correct |
13 ms |
15992 KB |
Output is correct |
3 |
Correct |
13 ms |
15992 KB |
Output is correct |
4 |
Correct |
13 ms |
15992 KB |
Output is correct |
5 |
Correct |
13 ms |
15992 KB |
Output is correct |
6 |
Correct |
13 ms |
15992 KB |
Output is correct |
7 |
Correct |
13 ms |
15992 KB |
Output is correct |
8 |
Correct |
13 ms |
15992 KB |
Output is correct |
9 |
Correct |
13 ms |
15992 KB |
Output is correct |
10 |
Correct |
13 ms |
15992 KB |
Output is correct |
11 |
Correct |
12 ms |
15992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
15992 KB |
Output is correct |
2 |
Correct |
13 ms |
15992 KB |
Output is correct |
3 |
Correct |
13 ms |
15992 KB |
Output is correct |
4 |
Correct |
13 ms |
15992 KB |
Output is correct |
5 |
Correct |
13 ms |
15992 KB |
Output is correct |
6 |
Correct |
13 ms |
15992 KB |
Output is correct |
7 |
Correct |
13 ms |
15992 KB |
Output is correct |
8 |
Correct |
13 ms |
15992 KB |
Output is correct |
9 |
Correct |
13 ms |
15992 KB |
Output is correct |
10 |
Correct |
13 ms |
15992 KB |
Output is correct |
11 |
Correct |
12 ms |
15992 KB |
Output is correct |
12 |
Correct |
13 ms |
15996 KB |
Output is correct |
13 |
Correct |
15 ms |
15992 KB |
Output is correct |
14 |
Correct |
14 ms |
15992 KB |
Output is correct |
15 |
Correct |
14 ms |
15992 KB |
Output is correct |
16 |
Correct |
13 ms |
15992 KB |
Output is correct |
17 |
Correct |
13 ms |
15992 KB |
Output is correct |
18 |
Correct |
13 ms |
15992 KB |
Output is correct |
19 |
Correct |
13 ms |
15996 KB |
Output is correct |
20 |
Correct |
13 ms |
15992 KB |
Output is correct |
21 |
Correct |
12 ms |
15992 KB |
Output is correct |
22 |
Correct |
13 ms |
15992 KB |
Output is correct |
23 |
Correct |
13 ms |
15992 KB |
Output is correct |
24 |
Correct |
13 ms |
15992 KB |
Output is correct |
25 |
Correct |
13 ms |
15992 KB |
Output is correct |
26 |
Correct |
12 ms |
15992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
15992 KB |
Output is correct |
2 |
Correct |
13 ms |
15992 KB |
Output is correct |
3 |
Correct |
13 ms |
15992 KB |
Output is correct |
4 |
Correct |
13 ms |
15992 KB |
Output is correct |
5 |
Correct |
13 ms |
15992 KB |
Output is correct |
6 |
Correct |
13 ms |
15992 KB |
Output is correct |
7 |
Correct |
13 ms |
15992 KB |
Output is correct |
8 |
Correct |
13 ms |
15992 KB |
Output is correct |
9 |
Correct |
13 ms |
15992 KB |
Output is correct |
10 |
Correct |
13 ms |
15992 KB |
Output is correct |
11 |
Correct |
12 ms |
15992 KB |
Output is correct |
12 |
Correct |
13 ms |
15996 KB |
Output is correct |
13 |
Correct |
15 ms |
15992 KB |
Output is correct |
14 |
Correct |
14 ms |
15992 KB |
Output is correct |
15 |
Correct |
14 ms |
15992 KB |
Output is correct |
16 |
Correct |
13 ms |
15992 KB |
Output is correct |
17 |
Correct |
13 ms |
15992 KB |
Output is correct |
18 |
Correct |
13 ms |
15992 KB |
Output is correct |
19 |
Correct |
13 ms |
15996 KB |
Output is correct |
20 |
Correct |
13 ms |
15992 KB |
Output is correct |
21 |
Correct |
12 ms |
15992 KB |
Output is correct |
22 |
Correct |
13 ms |
15992 KB |
Output is correct |
23 |
Correct |
13 ms |
15992 KB |
Output is correct |
24 |
Correct |
13 ms |
15992 KB |
Output is correct |
25 |
Correct |
13 ms |
15992 KB |
Output is correct |
26 |
Correct |
12 ms |
15992 KB |
Output is correct |
27 |
Correct |
15 ms |
16376 KB |
Output is correct |
28 |
Correct |
16 ms |
16376 KB |
Output is correct |
29 |
Correct |
15 ms |
16376 KB |
Output is correct |
30 |
Correct |
17 ms |
16376 KB |
Output is correct |
31 |
Correct |
17 ms |
16376 KB |
Output is correct |
32 |
Correct |
16 ms |
16376 KB |
Output is correct |
33 |
Correct |
15 ms |
16504 KB |
Output is correct |
34 |
Correct |
16 ms |
16376 KB |
Output is correct |
35 |
Correct |
15 ms |
16376 KB |
Output is correct |
36 |
Correct |
16 ms |
16376 KB |
Output is correct |
37 |
Correct |
16 ms |
16376 KB |
Output is correct |
38 |
Correct |
16 ms |
16504 KB |
Output is correct |
39 |
Correct |
17 ms |
16376 KB |
Output is correct |
40 |
Correct |
15 ms |
16376 KB |
Output is correct |
41 |
Correct |
16 ms |
16376 KB |
Output is correct |
42 |
Correct |
15 ms |
16376 KB |
Output is correct |
43 |
Correct |
16 ms |
16376 KB |
Output is correct |
44 |
Correct |
17 ms |
16376 KB |
Output is correct |
45 |
Correct |
17 ms |
16376 KB |
Output is correct |
46 |
Correct |
17 ms |
16504 KB |
Output is correct |
47 |
Correct |
16 ms |
16376 KB |
Output is correct |
48 |
Correct |
15 ms |
16376 KB |
Output is correct |
49 |
Correct |
15 ms |
16376 KB |
Output is correct |
50 |
Correct |
16 ms |
16376 KB |
Output is correct |
51 |
Correct |
15 ms |
16376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
15992 KB |
Output is correct |
2 |
Correct |
13 ms |
15992 KB |
Output is correct |
3 |
Correct |
13 ms |
15992 KB |
Output is correct |
4 |
Correct |
13 ms |
15992 KB |
Output is correct |
5 |
Correct |
13 ms |
15992 KB |
Output is correct |
6 |
Correct |
13 ms |
15992 KB |
Output is correct |
7 |
Correct |
13 ms |
15992 KB |
Output is correct |
8 |
Correct |
13 ms |
15992 KB |
Output is correct |
9 |
Correct |
13 ms |
15992 KB |
Output is correct |
10 |
Correct |
13 ms |
15992 KB |
Output is correct |
11 |
Correct |
12 ms |
15992 KB |
Output is correct |
12 |
Correct |
13 ms |
15996 KB |
Output is correct |
13 |
Correct |
15 ms |
15992 KB |
Output is correct |
14 |
Correct |
14 ms |
15992 KB |
Output is correct |
15 |
Correct |
14 ms |
15992 KB |
Output is correct |
16 |
Correct |
13 ms |
15992 KB |
Output is correct |
17 |
Correct |
13 ms |
15992 KB |
Output is correct |
18 |
Correct |
13 ms |
15992 KB |
Output is correct |
19 |
Correct |
13 ms |
15996 KB |
Output is correct |
20 |
Correct |
13 ms |
15992 KB |
Output is correct |
21 |
Correct |
12 ms |
15992 KB |
Output is correct |
22 |
Correct |
13 ms |
15992 KB |
Output is correct |
23 |
Correct |
13 ms |
15992 KB |
Output is correct |
24 |
Correct |
13 ms |
15992 KB |
Output is correct |
25 |
Correct |
13 ms |
15992 KB |
Output is correct |
26 |
Correct |
12 ms |
15992 KB |
Output is correct |
27 |
Correct |
15 ms |
16376 KB |
Output is correct |
28 |
Correct |
16 ms |
16376 KB |
Output is correct |
29 |
Correct |
15 ms |
16376 KB |
Output is correct |
30 |
Correct |
17 ms |
16376 KB |
Output is correct |
31 |
Correct |
17 ms |
16376 KB |
Output is correct |
32 |
Correct |
16 ms |
16376 KB |
Output is correct |
33 |
Correct |
15 ms |
16504 KB |
Output is correct |
34 |
Correct |
16 ms |
16376 KB |
Output is correct |
35 |
Correct |
15 ms |
16376 KB |
Output is correct |
36 |
Correct |
16 ms |
16376 KB |
Output is correct |
37 |
Correct |
16 ms |
16376 KB |
Output is correct |
38 |
Correct |
16 ms |
16504 KB |
Output is correct |
39 |
Correct |
17 ms |
16376 KB |
Output is correct |
40 |
Correct |
15 ms |
16376 KB |
Output is correct |
41 |
Correct |
16 ms |
16376 KB |
Output is correct |
42 |
Correct |
15 ms |
16376 KB |
Output is correct |
43 |
Correct |
16 ms |
16376 KB |
Output is correct |
44 |
Correct |
17 ms |
16376 KB |
Output is correct |
45 |
Correct |
17 ms |
16376 KB |
Output is correct |
46 |
Correct |
17 ms |
16504 KB |
Output is correct |
47 |
Correct |
16 ms |
16376 KB |
Output is correct |
48 |
Correct |
15 ms |
16376 KB |
Output is correct |
49 |
Correct |
15 ms |
16376 KB |
Output is correct |
50 |
Correct |
16 ms |
16376 KB |
Output is correct |
51 |
Correct |
15 ms |
16376 KB |
Output is correct |
52 |
Correct |
350 ms |
59896 KB |
Output is correct |
53 |
Correct |
357 ms |
59896 KB |
Output is correct |
54 |
Correct |
335 ms |
59896 KB |
Output is correct |
55 |
Correct |
352 ms |
60024 KB |
Output is correct |
56 |
Correct |
342 ms |
59892 KB |
Output is correct |
57 |
Correct |
336 ms |
59896 KB |
Output is correct |
58 |
Correct |
342 ms |
59852 KB |
Output is correct |
59 |
Correct |
347 ms |
60024 KB |
Output is correct |
60 |
Correct |
346 ms |
59900 KB |
Output is correct |
61 |
Correct |
347 ms |
59768 KB |
Output is correct |
62 |
Correct |
339 ms |
59896 KB |
Output is correct |
63 |
Correct |
343 ms |
60024 KB |
Output is correct |
64 |
Correct |
348 ms |
60004 KB |
Output is correct |
65 |
Correct |
344 ms |
60024 KB |
Output is correct |
66 |
Correct |
338 ms |
59896 KB |
Output is correct |
67 |
Correct |
336 ms |
59896 KB |
Output is correct |
68 |
Correct |
333 ms |
59916 KB |
Output is correct |