Submission #549528

# Submission time Handle Problem Language Result Execution time Memory
549528 2022-04-16T02:28:05 Z Soul234 Art Exhibition (JOI18_art) C++14
100 / 100
198 ms 25028 KB
#include<bits/stdc++.h>
using namespace std;

void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << h; if(sizeof...(t)) cerr << ", ";
    DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL

#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define tcT template<class T
#define nl "\n"

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using str = string;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;

void setIO(string NAME = "") {
    cin.tie(0)->sync_with_stdio(0);
    if(sz(NAME)) {
        freopen((NAME + ".inp").c_str(),"r",stdin);
        freopen((NAME + ".out").c_str(),"w",stdout);
    }
}

tcT> bool ckmax(T&a, const T&b) {
    return b > a ? a = b, 1 : 0;
}

const int MX = 5e5+5;
int N;
pair<ll,ll> A[MX];
ll sum = 0, ans;

void solve() {
    cin>>N;
    FOR(i,1,N+1) cin>>A[i].first>>A[i].second;
    priority_queue<ll> pq;
    sort(A+1,A+N+1);
    FOR(i,1,N+1) {
        pq.push(-sum+A[i].first);
        sum += A[i].second;
        ckmax(ans, sum - A[i].first + pq.top());
    }
    cout << ans << nl;
}

int main() {
    setIO();

    int t=1;
    //cin>>t;
    while(t-->0) {
        solve();
    }

    return 0;
}

Compilation message

art.cpp: In function 'void setIO(std::string)':
art.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen((NAME + ".inp").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen((NAME + ".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 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 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 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 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 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 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 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 336 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 332 KB Output is correct
20 Correct 1 ms 336 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 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 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 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 336 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 332 KB Output is correct
20 Correct 1 ms 336 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 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 520 KB Output is correct
30 Correct 3 ms 520 KB Output is correct
31 Correct 2 ms 596 KB Output is correct
32 Correct 2 ms 644 KB Output is correct
33 Correct 3 ms 596 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 3 ms 596 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 2 ms 592 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 2 ms 596 KB Output is correct
42 Correct 2 ms 596 KB Output is correct
43 Correct 2 ms 576 KB Output is correct
44 Correct 2 ms 516 KB Output is correct
45 Correct 2 ms 596 KB Output is correct
46 Correct 2 ms 568 KB Output is correct
47 Correct 2 ms 596 KB Output is correct
48 Correct 3 ms 596 KB Output is correct
49 Correct 2 ms 596 KB Output is correct
50 Correct 2 ms 612 KB Output is correct
51 Correct 2 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 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 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 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 336 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 332 KB Output is correct
20 Correct 1 ms 336 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 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 520 KB Output is correct
30 Correct 3 ms 520 KB Output is correct
31 Correct 2 ms 596 KB Output is correct
32 Correct 2 ms 644 KB Output is correct
33 Correct 3 ms 596 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 3 ms 596 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 2 ms 592 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 2 ms 596 KB Output is correct
42 Correct 2 ms 596 KB Output is correct
43 Correct 2 ms 576 KB Output is correct
44 Correct 2 ms 516 KB Output is correct
45 Correct 2 ms 596 KB Output is correct
46 Correct 2 ms 568 KB Output is correct
47 Correct 2 ms 596 KB Output is correct
48 Correct 3 ms 596 KB Output is correct
49 Correct 2 ms 596 KB Output is correct
50 Correct 2 ms 612 KB Output is correct
51 Correct 2 ms 568 KB Output is correct
52 Correct 196 ms 24872 KB Output is correct
53 Correct 198 ms 24932 KB Output is correct
54 Correct 179 ms 24984 KB Output is correct
55 Correct 183 ms 25024 KB Output is correct
56 Correct 191 ms 24992 KB Output is correct
57 Correct 176 ms 25028 KB Output is correct
58 Correct 175 ms 24980 KB Output is correct
59 Correct 175 ms 25028 KB Output is correct
60 Correct 171 ms 25012 KB Output is correct
61 Correct 179 ms 24800 KB Output is correct
62 Correct 188 ms 24936 KB Output is correct
63 Correct 178 ms 24988 KB Output is correct
64 Correct 174 ms 24920 KB Output is correct
65 Correct 175 ms 24940 KB Output is correct
66 Correct 178 ms 24968 KB Output is correct
67 Correct 175 ms 24932 KB Output is correct
68 Correct 173 ms 24956 KB Output is correct