Submission #1004654

# Submission time Handle Problem Language Result Execution time Memory
1004654 2024-06-21T11:33:17 Z zh_h Art Exhibition (JOI18_art) C++17
100 / 100
785 ms 21004 KB
#include <bits/stdc++.h>
#define lint long long int
#define pb push_back
using namespace std;



int main(){

    lint n;
    cin >> n;
    vector<pair<lint, lint>> v;
    for(lint i = 0; i < n; i ++){
        lint temp1, temp2;
        cin >> temp1 >> temp2;
        v.pb({temp1, temp2});
    }
    sort(v.begin(), v.end());

    // cout << endl;
    // for(auto i : v){
        // cout << i.first << " " << i.second << endl;
    // }
    // cout << endl;

    lint curSUM = v[0].second;
    lint globalSUM = v[0].second;
    lint curMAX = v[0].first, curMIN = v[0].first;
    // int globalMAX = v[0].second, globalMIN = v[0].second;
    lint EndIndex;

    // cout << curSUM << " " << globalSUM << endl;
    for(int i = 1; i < n; i ++){
        // curSUM = max(v[i], curSUM + v[i]);
        
        if(v[i].second > (curSUM + v[i].second - v[i].first + curMAX)){ //* what about the equal case?
            curSUM = v[i].second;
            curMIN = v[i].first;
            curMAX = v[i].first;
        }
        else{
            curSUM += (v[i].second-v[i].first+curMAX);
            curMAX = v[i].first;
        }

        if(curSUM > globalSUM){
            globalSUM = curSUM;
            EndIndex = i;
        }

        // cout << curSUM << " " << globalSUM << endl;
    }

    cout << globalSUM;

    // lint StartIndex = EndIndex;

    // while(true){
    //     globalSUM -= v[StartIndex].second;
    //     if(globalSUM == 0){break;}
    //     StartIndex--;
    // }


    
    // cout << endl;
    // cout << StartIndex << " " << EndIndex;

    // int n;
    // cin >> n;
    // vector<int> v;
    // for(int i = 0; i < n; i ++){
    //     int temp;
    //     cin >> temp;
    //     v.pb(temp);
    // }

    // int curMax = v[0], globalMax = v[0], EndIndex;

    // for(int i = 1; i < n; i ++){
    //     curMax = max(v[i], v[i] + curMax);

    //     if(curMax > globalMax){
    //         globalMax = curMax;
    //         EndIndex = i;
    //     }
    // }
    // // cout << "globalMax = " << globalMax << endl;
    // int StartIndex = EndIndex;
    // // cout << StartIndex << endl;
    // while(globalMax > 0){
    //     // cout << StartIndex << " " << globalMax << " ";
    //     globalMax -= v[StartIndex];
    //     // cout << globalMax << endl;
    //     StartIndex--;
    // }
    // // cout << endl;
    // StartIndex++;

    // for(int i = StartIndex; i <= EndIndex; i ++){
    //     cout << v[i] << " ";
    // }
    // cout << endl;

}

Compilation message

art.cpp: In function 'int main()':
art.cpp:28:31: warning: variable 'curMIN' set but not used [-Wunused-but-set-variable]
   28 |     lint curMAX = v[0].first, curMIN = v[0].first;
      |                               ^~~~~~
art.cpp:30:10: warning: variable 'EndIndex' set but not used [-Wunused-but-set-variable]
   30 |     lint EndIndex;
      |          ^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 344 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 432 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 344 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 432 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 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 344 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 444 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 432 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 344 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 432 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 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 344 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 444 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 432 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 4 ms 604 KB Output is correct
28 Correct 4 ms 604 KB Output is correct
29 Correct 4 ms 604 KB Output is correct
30 Correct 4 ms 604 KB Output is correct
31 Correct 5 ms 608 KB Output is correct
32 Correct 3 ms 708 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 4 ms 572 KB Output is correct
36 Correct 5 ms 604 KB Output is correct
37 Correct 4 ms 584 KB Output is correct
38 Correct 4 ms 612 KB Output is correct
39 Correct 4 ms 608 KB Output is correct
40 Correct 4 ms 608 KB Output is correct
41 Correct 3 ms 668 KB Output is correct
42 Correct 3 ms 696 KB Output is correct
43 Correct 4 ms 604 KB Output is correct
44 Correct 3 ms 608 KB Output is correct
45 Correct 4 ms 600 KB Output is correct
46 Correct 3 ms 608 KB Output is correct
47 Correct 4 ms 608 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 3 ms 608 KB Output is correct
50 Correct 4 ms 608 KB Output is correct
51 Correct 4 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 344 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 432 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 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 344 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 444 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 432 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 4 ms 604 KB Output is correct
28 Correct 4 ms 604 KB Output is correct
29 Correct 4 ms 604 KB Output is correct
30 Correct 4 ms 604 KB Output is correct
31 Correct 5 ms 608 KB Output is correct
32 Correct 3 ms 708 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 4 ms 572 KB Output is correct
36 Correct 5 ms 604 KB Output is correct
37 Correct 4 ms 584 KB Output is correct
38 Correct 4 ms 612 KB Output is correct
39 Correct 4 ms 608 KB Output is correct
40 Correct 4 ms 608 KB Output is correct
41 Correct 3 ms 668 KB Output is correct
42 Correct 3 ms 696 KB Output is correct
43 Correct 4 ms 604 KB Output is correct
44 Correct 3 ms 608 KB Output is correct
45 Correct 4 ms 600 KB Output is correct
46 Correct 3 ms 608 KB Output is correct
47 Correct 4 ms 608 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 3 ms 608 KB Output is correct
50 Correct 4 ms 608 KB Output is correct
51 Correct 4 ms 604 KB Output is correct
52 Correct 332 ms 20892 KB Output is correct
53 Correct 330 ms 20868 KB Output is correct
54 Correct 353 ms 20908 KB Output is correct
55 Correct 333 ms 20896 KB Output is correct
56 Correct 311 ms 20908 KB Output is correct
57 Correct 785 ms 20872 KB Output is correct
58 Correct 295 ms 20900 KB Output is correct
59 Correct 305 ms 20824 KB Output is correct
60 Correct 291 ms 20876 KB Output is correct
61 Correct 298 ms 20780 KB Output is correct
62 Correct 302 ms 21004 KB Output is correct
63 Correct 293 ms 20912 KB Output is correct
64 Correct 310 ms 20908 KB Output is correct
65 Correct 347 ms 20984 KB Output is correct
66 Correct 316 ms 20904 KB Output is correct
67 Correct 303 ms 20924 KB Output is correct
68 Correct 320 ms 20904 KB Output is correct