Submission #701376

# Submission time Handle Problem Language Result Execution time Memory
701376 2023-02-21T05:30:28 Z mychecksedad Art Exhibition (JOI18_art) C++17
100 / 100
203 ms 28756 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1e6+100, M = 1e5+10, K = 20;

int n;
pair<ll, ll> a[N];
ll pref[N], dp[N];
void solve(){
  cin >> n;
  for(int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;
  sort(a + 1, a + n + 1);
  pref[0] = dp[0] = 0;
  for(int i = 1; i <= n; ++i){
    pref[i] = pref[i - 1] + a[i].second - (i == n ? 0 : a[i + 1].first - a[i].first);
    dp[i] = min(pref[i], dp[i - 1]);
  }
  ll ans = 0;
  for(int i = 1; i <= n; ++i){
    ans = max(ans, pref[i] + (i == n ? 0 : a[i + 1].first - a[i].first) - dp[i - 1]);
  }
  cout << ans;
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int T = 1, aa;
  // cin >> T;aa=T;
  while(T--){
    // cout << "Case #" << aa-T << ": ";
    solve();
    cout << '\n';
  }
  return 0;
 
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:34:14: warning: unused variable 'aa' [-Wunused-variable]
   34 |   int T = 1, aa;
      |              ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 328 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 340 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 340 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 332 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 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 328 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 340 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 340 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 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 3 ms 592 KB Output is correct
28 Correct 3 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 2 ms 616 KB Output is correct
32 Correct 2 ms 596 KB Output is correct
33 Correct 3 ms 576 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 2 ms 596 KB Output is correct
37 Correct 2 ms 576 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 2 ms 576 KB Output is correct
40 Correct 3 ms 596 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 3 ms 620 KB Output is correct
43 Correct 2 ms 592 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 2 ms 596 KB Output is correct
46 Correct 2 ms 596 KB Output is correct
47 Correct 4 ms 596 KB Output is correct
48 Correct 3 ms 596 KB Output is correct
49 Correct 3 ms 592 KB Output is correct
50 Correct 3 ms 596 KB Output is correct
51 Correct 3 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 328 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 340 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 340 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 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 3 ms 592 KB Output is correct
28 Correct 3 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 2 ms 616 KB Output is correct
32 Correct 2 ms 596 KB Output is correct
33 Correct 3 ms 576 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 2 ms 596 KB Output is correct
37 Correct 2 ms 576 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 2 ms 576 KB Output is correct
40 Correct 3 ms 596 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 3 ms 620 KB Output is correct
43 Correct 2 ms 592 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 2 ms 596 KB Output is correct
46 Correct 2 ms 596 KB Output is correct
47 Correct 4 ms 596 KB Output is correct
48 Correct 3 ms 596 KB Output is correct
49 Correct 3 ms 592 KB Output is correct
50 Correct 3 ms 596 KB Output is correct
51 Correct 3 ms 596 KB Output is correct
52 Correct 203 ms 24036 KB Output is correct
53 Correct 182 ms 28628 KB Output is correct
54 Correct 167 ms 28608 KB Output is correct
55 Correct 171 ms 28648 KB Output is correct
56 Correct 184 ms 28756 KB Output is correct
57 Correct 165 ms 28624 KB Output is correct
58 Correct 178 ms 28600 KB Output is correct
59 Correct 183 ms 28616 KB Output is correct
60 Correct 177 ms 28624 KB Output is correct
61 Correct 169 ms 28440 KB Output is correct
62 Correct 174 ms 28588 KB Output is correct
63 Correct 167 ms 28624 KB Output is correct
64 Correct 167 ms 28628 KB Output is correct
65 Correct 175 ms 28556 KB Output is correct
66 Correct 167 ms 28592 KB Output is correct
67 Correct 172 ms 28540 KB Output is correct
68 Correct 178 ms 28616 KB Output is correct