Submission #1108380

#TimeUsernameProblemLanguageResultExecution timeMemory
1108380vjudge1Art Exhibition (JOI18_art)C++17
100 / 100
151 ms18368 KiB
#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const int maxn = 5e5 + 10;
pair<int, int> p[maxn];
int n;
int pre[maxn];
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #define TASK "TASK"
    if (fopen(TASK".INP", "r")){
        freopen(TASK".INP", "r", stdin);
        freopen(TASK".OUT", "w", stdout);
    }
    cin >> n;
    for(int i = 1; i <= n; ++ i) {
        cin >> p[i].first >> p[i].second;
    }
    sort(p + 1, p + n + 1);
    for(int i = 1; i <= n; ++ i) pre[i] = pre[i - 1] + p[i].second;
    priority_queue<int, vector<int>, greater<int>> pq;
    int ans = 0;
    for(int i = 1; i <= n; ++ i) {
        pq.push(pre[i - 1] - p[i].first);
        ans = max(ans, pre[i] - p[i].first - pq.top());
    }
    cout << ans;
    return 0;
}
//                                                                         ▒███████▓▒░
//                                                                      ███▓░░░░░░░████▓
//                                                                    ░██░░░░░░░░███▓ ░▒
//                                ██████████████████████████          ██░░░░░░░██▓▓█████▒
//                          ███████░░░░░░░███░░░░░░░░░░░░░░░███▓    ▓███░░░░░████▒░░░▒████
//              █████████████░░░░░░░░░░░░██░░░░░░░░░░░░░░░░░░████████▓▓██░░░███░░░░░░░░░░██░
//              ▒██░░░░░░░░░░░░░░░░░░░░░░█░░░░░░░░░░░░░░░░░░░▓██████▓▓▓▓██░██▓░░░░░░░░░░░░▒█
//               ░███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██▓▓▓▓██▓███████▓████████░░░░░░█▓
//                  ███▓░░░░░░██░░░░░░░█░░░░░░░░░░░░░█▓░░░░░▒█▓▓▓▓▓▓██▓▓███▓▓▓█▓    ███░░░██▒
//                    █▓░░░░██░░░░░░░░█▓░░░░░░░░░░░░░░█▓░░░░░░███▓▓▓██▓▓▓▓▓▓▓██      ░█▓░███
//                  ▒█▒░░░██░░░░░░░░░██░░░░░░░░░░░░░░▓██▓░░░░░░▒█████████▓▓▓███      ▓████░
//                 ░█▒░░░██░░░░░░░░░░██░░░░░░░░░░░░░░████░░░░░░░░░░▒█████████░▓█     ███
//                 ██░░░██░░░░░░░░░░▒█▒░░░░░░░░░░░░░██░▓██░░░░░░░░░░░░░░░░█▓░░░█▓
//                ▒█▒░░░█▒░░░░░░░░░░▒█▒░░░░░░░░░░░░▓██░░▒██░░░░░░░░░░░░░░░░░░░░▒█░
//                ██░░░███░░░░░░░░░░██▒░░░░░░░░░░░▒██░░░░░██░░░░░░░░░░░░░░░░░░░░██
//               ██░░░▒███░░░░░░░░████▓░░░░░░█░░░▒██▒░░░░░░██░░░░░░░░█▒▒██░░░░░░██▓
//              ██░░░░████░░░░░░██▓  ██░░░░░██░░▒██░█▒░░░░░░██░░░░░░░██▒▒██░░░░░░██░
//             ██░░░░██░▒██░░░░█▓    ▒█▒░░░███░▓█▒  ▓█░░░░░░▒█▒░░░░░░▒██░░██░░░░░░██░
//           ░█▒░░░░██░░░███▒▒█▒      ▓█░░░█████░    ▓██░░░░░██░░░░░░░██░░░██░░░░░░████▒    ▓
//          ██░░░░░██▒░░▓█░████        ▓█▓▒█░█▓       ░██▓░░░░██░░░░░░▓█▓░░▒██▓░░░░░░░▓██████
//        ░█▒░░░░░██▓░░██               ░███ ░          ▒███░░██░░░░░░▒██░░░████▓░░░░░░▒██▓
//       ███████████░▒█▒  ██                               ▒████▒░░░░░▒██░░░░██▒▓██████▓
//               ██░██░                                        ██░░░░░███░░░░▒██░░██
//              ▒█▓▒█░                                         ▓█░░░░▒██▓░░░░░██▓░░█▒
//              ██░█▓                                     ██   ▓▓░░░▒███▒░░░░░▒██░░█▓
//              ██░▒█              ██████████████              █▒░░█████░░░░░░░██░░█▒
//              ██░░██             █▓▓▓▓▓▓▓▓▓▓▓██             ░█░▓██▓██▓░░░░░░░██░░█▒
//              ██░████░            ██▓▓▓▓▓▓▓▓██              █████ ░██░░░░░░░███░░█░
//              ██████▓██             █▓▓▓▓▓▓██              ▓█▓░  ▒█▓░░░░░░░░██░░░█░
//               ███ ██░░██░            █████                    ░██░░░░░░░░░██▒░░░█░
//                   ██░░░░███░                              ░░██▓░░░░░░░░░░██▒░░░░█░
//                    ██░░▓░░░███▓░                       ▒███▓░░░░░░░░░░░███░░░░░░█▒
//                     ██████▓░░░▒████▓░                   ░█▓░░░░░░░░░░██▓ ██▓░░░░▒█
//                      ▓██ ░████████████████▓▓░░░░░░░░░░▒██████▓▒▒▒▓██▓     ▒███▒░░██
//                        ▒ ▒█████░ ▓█▓▓▓▓███▓████████████░░░▒█████░░▒█▒         ▒████
//                       ▒▓████▓    ▒█▓▓▓▓▓▓███▓▓▓▓▓▓▓▓▓█       ▓███████
//                       ▓███▓▓▓▓   ░█▓▓▓▓███▓▓▓▓▓▓▓▓▓▓██      ▓▓▓▓▓████▓
//                    ░████░███▓▓▓█▓  ░████▓██▓██████████▓▒  ░▓▓▓▓████▓██▓
//                  ░███    ░█████   ██▓▓██▓▓▒███▓███▒   ███░▓▓▓▓███░▒████▒
//               ▒██▒░██   ██████     ███   ▓▓  ░█████    ░████████░ ░██░▓▓█▒                    ░██
//███████████████▒░░░░▒█░  ██░░░█░          ▒▓            ▓█░░░▒█░   ██░░▒▓████▓▓░               ████
// █▒░░░░░░░██▒░░░░░░░▒█░  ▒█▒░████▓▓▓▓█████████▒       ▓████▓██░   ██▓░░▓▓░░▒▓▓███░           ███░▒██
// ░██░░▒██▓░░░░░░░░░░▓██  ░██░   ░ ▒█▓▓▓▓▓▓▓▓▓▓██████████░   █▓   ██▒░░░▒▓░▒▓▓░░█████████████▓░░░░░██
//    ██▓░░░░░░░░░░▒██▓ █▓ ░█░   ███████████▓▓▓▓▓███████████████▒██████░░░▓▓▓▓░░░░░░░░███▒░░░░░░░░░██
//   ▓█░░░░░░░░▓██▒     ░█▓███████▓▓▓▓██████████████▓▓▓▓▓▓▓▓▓▓████▓    ▓██▓▓▓░░░░░░░░░░░░░▓██▒░░░███
//   █▒░░░░░░▓██          ████▓▓▓▓▓████ ██▓▓▓▓▓▓▓█░████▓▓▓▓▓▓▓████▒      ▓▓▓▓███▒░░░░░░░░░░░▒█████▒
//   █▓░░░░░██          ░███▓▓▓████▓   ██▓▓▓▓▓▓▓▓█▒  ░█████████▒ ██     ▓▓   ░▓  ███▒░░░░░░░░░███
//   ██▒░░░██           █▓▓██████    ░██▓▓▓▓▓▓▓▓▓█▒    ░███████████    ░▓▓▓▓▓▓▓▒    ▒██▒░░░░░░░██
//    ███░░█▓           ██▓█████████████████████████████▒ █████████                    ██░░░░░░██
//      ▓█████          ████████▒                         ░████████                      █▒░░░░██
//                      ░███████                           ███████▒                       █▒░░▓█
//                       ██████░                            ██████                        ██░▓█▒
//                        ▒███                                ███                         ████░
//

Compilation message (stderr)

art.cpp: In function 'int32_t main()':
art.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen(TASK".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...