Submission #753858

# Submission time Handle Problem Language Result Execution time Memory
753858 2023-06-06T08:31:47 Z emad234 Art Exhibition (JOI18_art) C++17
100 / 100
237 ms 32752 KB
#include <bits/stdc++.h>
#define all(v) ((v).begin(),(v).end())
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
const ll mxN = 2e6 + 1;
pair<ll,ll>a[mxN];
vector<pair<ll,ll>>v;
ll prfx[mxN];
signed main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  ll n;
  cin >>n;
  for(ll i = 0;i < n;i++) cin >>a[i].first>>a[i].second;
  ll ans = 0;
  sort(a,a + n);
  ll bf = -1;
  ll sum2 = 0;
  for(ll i = 0;i < n;i++){
    if(a[i].first != bf && bf != -1){
      v.push_back({bf,sum2});
      sum2 = 0;
    }
    sum2 += a[i].second;
    bf = a[i].first;
  }
  v.push_back({bf,sum2});
  // cout<<'\n';
  // for(auto x : v) cout<<x.first<<' '<<x.second<<'\n';
  prfx[0] = v[0].second;
  for(ll i = 1;i < n;i++){
    prfx[i] = prfx[i - 1] + v[i].second;
  }
  ll l = 0;
  ans = v[0].second;
  // cout<<ans<<'\n';
  for(ll i = 1;i < v.size();i++){
    ll x = 0;
    if(l != 0) x = prfx[l - 1];
    ll sum = prfx[i] - x - v[i].first + v[l].first;
    ll sum1 = v[i].second;
    if(sum1 >= sum){
      l = i;
    }
    ans = max(max(ans,sum),sum1);
  }
  cout<<ans<<'\n';
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:38:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   for(ll i = 1;i < v.size();i++){
      |                ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 3 ms 784 KB Output is correct
29 Correct 3 ms 708 KB Output is correct
30 Correct 3 ms 728 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 3 ms 732 KB Output is correct
33 Correct 3 ms 780 KB Output is correct
34 Correct 3 ms 724 KB Output is correct
35 Correct 2 ms 724 KB Output is correct
36 Correct 3 ms 732 KB Output is correct
37 Correct 2 ms 724 KB Output is correct
38 Correct 3 ms 724 KB Output is correct
39 Correct 2 ms 724 KB Output is correct
40 Correct 3 ms 724 KB Output is correct
41 Correct 2 ms 788 KB Output is correct
42 Correct 3 ms 724 KB Output is correct
43 Correct 2 ms 724 KB Output is correct
44 Correct 2 ms 724 KB Output is correct
45 Correct 2 ms 724 KB Output is correct
46 Correct 2 ms 724 KB Output is correct
47 Correct 4 ms 744 KB Output is correct
48 Correct 3 ms 732 KB Output is correct
49 Correct 3 ms 724 KB Output is correct
50 Correct 3 ms 724 KB Output is correct
51 Correct 3 ms 792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 3 ms 784 KB Output is correct
29 Correct 3 ms 708 KB Output is correct
30 Correct 3 ms 728 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 3 ms 732 KB Output is correct
33 Correct 3 ms 780 KB Output is correct
34 Correct 3 ms 724 KB Output is correct
35 Correct 2 ms 724 KB Output is correct
36 Correct 3 ms 732 KB Output is correct
37 Correct 2 ms 724 KB Output is correct
38 Correct 3 ms 724 KB Output is correct
39 Correct 2 ms 724 KB Output is correct
40 Correct 3 ms 724 KB Output is correct
41 Correct 2 ms 788 KB Output is correct
42 Correct 3 ms 724 KB Output is correct
43 Correct 2 ms 724 KB Output is correct
44 Correct 2 ms 724 KB Output is correct
45 Correct 2 ms 724 KB Output is correct
46 Correct 2 ms 724 KB Output is correct
47 Correct 4 ms 744 KB Output is correct
48 Correct 3 ms 732 KB Output is correct
49 Correct 3 ms 724 KB Output is correct
50 Correct 3 ms 724 KB Output is correct
51 Correct 3 ms 792 KB Output is correct
52 Correct 184 ms 32552 KB Output is correct
53 Correct 188 ms 32700 KB Output is correct
54 Correct 190 ms 32740 KB Output is correct
55 Correct 189 ms 32680 KB Output is correct
56 Correct 197 ms 32708 KB Output is correct
57 Correct 195 ms 32648 KB Output is correct
58 Correct 179 ms 32572 KB Output is correct
59 Correct 189 ms 32676 KB Output is correct
60 Correct 186 ms 32676 KB Output is correct
61 Correct 178 ms 32444 KB Output is correct
62 Correct 195 ms 32644 KB Output is correct
63 Correct 184 ms 32584 KB Output is correct
64 Correct 177 ms 32612 KB Output is correct
65 Correct 178 ms 32656 KB Output is correct
66 Correct 186 ms 32676 KB Output is correct
67 Correct 237 ms 32564 KB Output is correct
68 Correct 178 ms 32752 KB Output is correct