Submission #679172

# Submission time Handle Problem Language Result Execution time Memory
679172 2023-01-07T16:08:59 Z speedyArda Art Exhibition (JOI18_art) C++14
100 / 100
529 ms 19916 KB
#pragma GCC optimize ("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"
#define pb push_back
#define vll vector<long long>
#define vb vector<bool>
#define vi vector<int>
#define vs vector<string>
#define vpii vector< pair<int, int> >
#define pii pair<int, int>
#define pbb pair<bool, bool>
#define pll pair<long long, long long>
#define vvi vector< vector<int> > 
#define ld long double
#define mp make_pair
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;
const int MAXN = 5e5+5;
pair<ll, ll> in[MAXN];
// Solution O(n). Add the differences between sizes as negatives in the array. The rest is Kadane Algorithm. (Maximum contiguous sum)
int main() 
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)  
        cin >> in[i].first >> in[i].second;
    sort(in, in + n);
    reverse(in, in + n);
    vector< ll > elems;
    elems.pb(in[0].second);
    for(int i = 1; i < n; i++)
    {
        if(in[i].first != in[i - 1].first)
            elems.pb(in[i].first - in[i - 1].first);
        elems.pb(in[i].second);
    } 
    ll ans = 0, temp = 0;
    for(int i = 0; i < elems.size(); i++)
    {
        temp += elems[i];
        ans = max(ans, temp);
        if(temp < 0)
            temp = 0;
    }

    cout << ans << "\n";
}

Compilation message

art.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
art.cpp: In function 'int main()':
art.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i = 0; i < elems.size(); i++)
      |                    ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 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 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 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 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 272 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 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 0 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 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 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 272 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 5 ms 680 KB Output is correct
28 Correct 5 ms 724 KB Output is correct
29 Correct 6 ms 644 KB Output is correct
30 Correct 6 ms 724 KB Output is correct
31 Correct 6 ms 724 KB Output is correct
32 Correct 5 ms 724 KB Output is correct
33 Correct 5 ms 704 KB Output is correct
34 Correct 5 ms 704 KB Output is correct
35 Correct 6 ms 724 KB Output is correct
36 Correct 6 ms 724 KB Output is correct
37 Correct 5 ms 724 KB Output is correct
38 Correct 5 ms 724 KB Output is correct
39 Correct 5 ms 608 KB Output is correct
40 Correct 5 ms 700 KB Output is correct
41 Correct 5 ms 644 KB Output is correct
42 Correct 6 ms 700 KB Output is correct
43 Correct 6 ms 676 KB Output is correct
44 Correct 7 ms 632 KB Output is correct
45 Correct 5 ms 700 KB Output is correct
46 Correct 5 ms 724 KB Output is correct
47 Correct 5 ms 704 KB Output is correct
48 Correct 5 ms 620 KB Output is correct
49 Correct 6 ms 708 KB Output is correct
50 Correct 5 ms 724 KB Output is correct
51 Correct 5 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 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 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 272 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 5 ms 680 KB Output is correct
28 Correct 5 ms 724 KB Output is correct
29 Correct 6 ms 644 KB Output is correct
30 Correct 6 ms 724 KB Output is correct
31 Correct 6 ms 724 KB Output is correct
32 Correct 5 ms 724 KB Output is correct
33 Correct 5 ms 704 KB Output is correct
34 Correct 5 ms 704 KB Output is correct
35 Correct 6 ms 724 KB Output is correct
36 Correct 6 ms 724 KB Output is correct
37 Correct 5 ms 724 KB Output is correct
38 Correct 5 ms 724 KB Output is correct
39 Correct 5 ms 608 KB Output is correct
40 Correct 5 ms 700 KB Output is correct
41 Correct 5 ms 644 KB Output is correct
42 Correct 6 ms 700 KB Output is correct
43 Correct 6 ms 676 KB Output is correct
44 Correct 7 ms 632 KB Output is correct
45 Correct 5 ms 700 KB Output is correct
46 Correct 5 ms 724 KB Output is correct
47 Correct 5 ms 704 KB Output is correct
48 Correct 5 ms 620 KB Output is correct
49 Correct 6 ms 708 KB Output is correct
50 Correct 5 ms 724 KB Output is correct
51 Correct 5 ms 724 KB Output is correct
52 Correct 504 ms 19916 KB Output is correct
53 Correct 514 ms 19712 KB Output is correct
54 Correct 513 ms 19876 KB Output is correct
55 Correct 529 ms 19736 KB Output is correct
56 Correct 503 ms 19784 KB Output is correct
57 Correct 496 ms 19768 KB Output is correct
58 Correct 509 ms 19696 KB Output is correct
59 Correct 510 ms 19804 KB Output is correct
60 Correct 509 ms 19768 KB Output is correct
61 Correct 508 ms 19856 KB Output is correct
62 Correct 502 ms 19768 KB Output is correct
63 Correct 501 ms 19776 KB Output is correct
64 Correct 508 ms 19840 KB Output is correct
65 Correct 502 ms 19748 KB Output is correct
66 Correct 509 ms 19752 KB Output is correct
67 Correct 526 ms 19776 KB Output is correct
68 Correct 516 ms 19732 KB Output is correct