Submission #1321925

#TimeUsernameProblemLanguageResultExecution timeMemory
1321925segfaultedArt Exhibition (JOI18_art)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")

class Solve {
public:
    void solve() {
        int tuxn;
        cin >> tuxn;
        vector<pair<int,int>> tuxv(tuxn);
        for (int tuxi = 0; tuxi < tuxn; tuxi++) {
            int tuxa, tuxb;
            cin >> tuxa >> tuxb;
            tuxv[tuxi] = {tuxa, tuxb};
        }

        sort(tuxv.begin(), tuxv.end());

        int tuxans = LLONG_MIN;
        int tuxsum = 0, tuxl = 0;

        for (int tuxr = 0; tuxr < tuxn; tuxr++) {
            tuxsum += tuxv[tuxr].second;

            while (tuxv[tuxr].first - tuxv[tuxl].first > 1e18) {
                tuxsum -= tuxv[tuxl].second;
                tuxl++;
            }

            tuxans = max(tuxans, tuxsum - (tuxv[tuxr].first - tuxv[tuxl].first));
        }

        cout << tuxans << endl;
    }
};

signed main(signed argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    if (argc > 1 && string(argv[1]) == "allyst") {
        freopen("in.case", "r", stdin);
        freopen("out.case", "w", stdout);
    }

    Solve tuxz;
    tuxz.solve();
}

Compilation message (stderr)

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