Submission #972172

# Submission time Handle Problem Language Result Execution time Memory
972172 2024-04-30T08:07:37 Z Hectorungo_18 Art Exhibition (JOI18_art) C++14
0 / 100
1 ms 344 KB
#include <iostream>
#include <bits/stdc++.h>
#include <list>
#include <set>
#include <cstdio>

using namespace std;
#define int long long
#define f first
#define s second 


void solve(){
    int n;
    cin >> n;
    vector<pair<int, int>> v(n+1, {0, 0});

    for(int i = 1; i <= n; i++) cin >> v[i].f >> v[i].s;

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


    vector<int> ps(n+1, 0);
    ps[1] = v[1].s;
    // cout << ps[1] << " ";
    for(int i = 2; i <= n; i++){
        ps[i] = ps[i-1]+v[i].s;
        ps[i]+=v[i-1].f-v[i].f;
        // cout << ps[i] << " ";
    }
    // cout << endl;
    int ans = ps[1];
    int pos = 0;
    int mn = (int) 0;
    if(ps[1] < mn){
        mn = ps[1];
        pos = 1;
    }
    for(int i = 2; i <= n; i++){
        if(ps[i]-mn+v[pos].s > ans){
            ans = ps[i]-mn+v[pos].s;
        }
        if(mn > ps[i]){
            mn = ps[i];
            pos = i;
        }
    }

    cout << ans << endl;

}

signed main() {
    int t = 1;
    // cin >> t;
    while(t--) solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -