Submission #943517

# Submission time Handle Problem Language Result Execution time Memory
943517 2024-03-11T14:49:17 Z vjudge1 Art Exhibition (JOI18_art) C++17
0 / 100
1 ms 2396 KB
# include <bits/stdc++.h>

# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
# define deb(x) cerr << #x  << " = " << x << endl; 
# define pll pair <ll, ll>
# define pii pair <int, int>
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll maxn = (ll)5e5 + 3;
const ll inf  = (ll)2e18 + 0;
const ll mod  = (ll)1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
const bool T = 0;

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void Freopen () {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int n;
pii p[maxn];
ll pref[maxn];

void ma1n () {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i].ff >> p[i].ss;
    }
    sort(p + 1, p + 1 + n);
    // for (int i = 1; i <= n; ++i) {
    //     cout << p[i].ff << ' ' << p[i].ss << nl;
    // }
    ll ans = 0, mx = -inf;
    for (int i = 1; i <= n; ++i) {
        pref[i] = pref[i - 1] + p[i].ss;
        ll cur = pref[i] - p[i].ff + mx;
        // cout << i << ' ' << cur << ' ' << mx << nl;
        ans = max(ans, cur);
        mx = max(mx, -pref[i - 1] + p[i].ff);
    }
    cout << ans << nl;
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
   // Freopen();
    int ttt = 1;
    if (T) cin >> ttt;
    for (int test = 1; test <= ttt; ++test) {
//      cout << "Case " << test << ":" << '\n';
        ma1n();
    }
    return 0;
}

Compilation message

art.cpp: In function 'void Freopen()':
art.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -