Submission #285474

#TimeUsernameProblemLanguageResultExecution timeMemory
285474BeanZArt Exhibition (JOI18_art)C++14
100 / 100
233 ms28904 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define endl '\n'

const int N = 4e6 + 20;
const int mod = 998244353;
pair<ll, ll> a[500005];
ll sum[500005];
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("VietCT.INP", "r")){
                freopen("VietCT.INP", "r", stdin);
                freopen("VietCT.OUT", "w", stdout);
        }
        ll n;
        cin >> n;
        for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
        sort(a + 1, a + n + 1);
        priority_queue<ll, vector<ll>, greater<ll>> pq;
        ll ans = 0;
        for (int i = 1; i <= n; i++){
                sum[i] = sum[i - 1] + a[i].second;
                if (pq.size()){
                        ans = max(ans, sum[i] - a[i].first - pq.top());
                }
                ans = max(ans, a[i].second);
                pq.push({sum[i - 1] - a[i].first});
        }
        cout << ans;
}
/*
*/

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:16:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   16 |                 freopen("VietCT.INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:17:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   17 |                 freopen("VietCT.OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...