Submission #48953

# Submission time Handle Problem Language Result Execution time Memory
48953 2018-05-20T09:48:26 Z faishol27 Art Exhibition (JOI18_art) C++14
100 / 100
888 ms 9148 KB
#include  <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define PUB push_back
 
struct art{
    ll sz, val;
};
 
int N;
ll ans = 0, cnt = 0, pref[500005];
vector<art> data;

bool comp(art a, art b){
    if(a.sz == b.sz) return a.val < b.val;
    return a.sz < b.sz;
}

ll optimized(){
    cnt += data[1].val;
    ans = max(cnt, ans);

    for(int i=2;i<=N;i++){
        cnt += data[i].val-(data[i].sz-data[i-1].sz);
        if(cnt <= 0 || cnt < data[i].val){
            cnt = data[i].val;
        }
        ans = max(ans, cnt);
    }
} 

ll bf(){
    cout << "== BF ==" << endl;
    for(int i=1;i<=N;i++) pref[i] = pref[i-1]+data[i].val;
    
    for(int i=1;i<=N;i++) for(int j=i;j<=N;j++){
        ll tmp = (pref[j]-pref[i-1])-(data[j].sz-data[i].sz);
        
        if(ans < tmp){
            cout << i << " " << j << " " << tmp << endl;
            ans = tmp;
        }
    }
}

int main(){
    cin >> N;
    data.PUB({0,0});
    for(int i=1;i<=N;i++){
        ll a, b;
        cin >> a >> b;
        data.PUB({a, b});
    }
 
    sort(data.begin(), data.end(), comp);
    
    optimized();
    cout << ans << endl;
    
    //bf();
    //cout << ans << endl;

}

Compilation message

art.cpp: In function 'll optimized()':
art.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type]
 } 
 ^
art.cpp: In function 'll bf()':
art.cpp:46:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 2 ms 560 KB Output is correct
10 Correct 2 ms 560 KB Output is correct
11 Correct 2 ms 560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 2 ms 560 KB Output is correct
10 Correct 2 ms 560 KB Output is correct
11 Correct 2 ms 560 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 3 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 3 ms 748 KB Output is correct
22 Correct 3 ms 748 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 3 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 2 ms 560 KB Output is correct
10 Correct 2 ms 560 KB Output is correct
11 Correct 2 ms 560 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 3 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 3 ms 748 KB Output is correct
22 Correct 3 ms 748 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 3 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 748 KB Output is correct
27 Correct 9 ms 764 KB Output is correct
28 Correct 11 ms 764 KB Output is correct
29 Correct 9 ms 764 KB Output is correct
30 Correct 11 ms 764 KB Output is correct
31 Correct 19 ms 764 KB Output is correct
32 Correct 9 ms 764 KB Output is correct
33 Correct 9 ms 764 KB Output is correct
34 Correct 10 ms 764 KB Output is correct
35 Correct 9 ms 808 KB Output is correct
36 Correct 10 ms 808 KB Output is correct
37 Correct 9 ms 808 KB Output is correct
38 Correct 10 ms 812 KB Output is correct
39 Correct 11 ms 812 KB Output is correct
40 Correct 13 ms 812 KB Output is correct
41 Correct 11 ms 812 KB Output is correct
42 Correct 9 ms 812 KB Output is correct
43 Correct 10 ms 812 KB Output is correct
44 Correct 12 ms 812 KB Output is correct
45 Correct 9 ms 828 KB Output is correct
46 Correct 11 ms 828 KB Output is correct
47 Correct 8 ms 828 KB Output is correct
48 Correct 8 ms 828 KB Output is correct
49 Correct 9 ms 828 KB Output is correct
50 Correct 9 ms 828 KB Output is correct
51 Correct 10 ms 828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 2 ms 560 KB Output is correct
10 Correct 2 ms 560 KB Output is correct
11 Correct 2 ms 560 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 3 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 3 ms 748 KB Output is correct
22 Correct 3 ms 748 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 3 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 748 KB Output is correct
27 Correct 9 ms 764 KB Output is correct
28 Correct 11 ms 764 KB Output is correct
29 Correct 9 ms 764 KB Output is correct
30 Correct 11 ms 764 KB Output is correct
31 Correct 19 ms 764 KB Output is correct
32 Correct 9 ms 764 KB Output is correct
33 Correct 9 ms 764 KB Output is correct
34 Correct 10 ms 764 KB Output is correct
35 Correct 9 ms 808 KB Output is correct
36 Correct 10 ms 808 KB Output is correct
37 Correct 9 ms 808 KB Output is correct
38 Correct 10 ms 812 KB Output is correct
39 Correct 11 ms 812 KB Output is correct
40 Correct 13 ms 812 KB Output is correct
41 Correct 11 ms 812 KB Output is correct
42 Correct 9 ms 812 KB Output is correct
43 Correct 10 ms 812 KB Output is correct
44 Correct 12 ms 812 KB Output is correct
45 Correct 9 ms 828 KB Output is correct
46 Correct 11 ms 828 KB Output is correct
47 Correct 8 ms 828 KB Output is correct
48 Correct 8 ms 828 KB Output is correct
49 Correct 9 ms 828 KB Output is correct
50 Correct 9 ms 828 KB Output is correct
51 Correct 10 ms 828 KB Output is correct
52 Correct 729 ms 8928 KB Output is correct
53 Correct 787 ms 8960 KB Output is correct
54 Correct 753 ms 8984 KB Output is correct
55 Correct 743 ms 9104 KB Output is correct
56 Correct 745 ms 9104 KB Output is correct
57 Correct 839 ms 9104 KB Output is correct
58 Correct 710 ms 9104 KB Output is correct
59 Correct 723 ms 9104 KB Output is correct
60 Correct 689 ms 9104 KB Output is correct
61 Correct 695 ms 9104 KB Output is correct
62 Correct 888 ms 9104 KB Output is correct
63 Correct 760 ms 9148 KB Output is correct
64 Correct 727 ms 9148 KB Output is correct
65 Correct 735 ms 9148 KB Output is correct
66 Correct 701 ms 9148 KB Output is correct
67 Correct 673 ms 9148 KB Output is correct
68 Correct 673 ms 9148 KB Output is correct