제출 #1110747

#제출 시각아이디문제언어결과실행 시간메모리
1110747luvnaArt Exhibition (JOI18_art)C++14
100 / 100
145 ms24764 KiB
#include<bits/stdc++.h>

#define all(v) v.begin(), v.end()
#define endl "\n"

using namespace std;

typedef long long ll;

const int N = 5e5 + 15;

int n;
pair<ll,ll> a[N];
ll pref[N];
ll ans = 0;

void solve(){
    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> a[i].first >> a[i].second;
    }

    sort(a + 1, a + 1 + n);

    for(int i = 1; i <= n; i++) pref[i] = pref[i-1] + a[i].second;

    ll maxx = -INT_MAX;

    for(int i = 1; i <= n; i++){
        maxx = max(maxx, a[i].first - pref[i-1]);
        ans = max(ans, pref[i] - a[i].first + maxx);
    }

    cout << ans;
}

signed main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(0); cout.tie(0);

    #define task "task"

    if(fopen(task".INP", "r")){
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }

    int t; t = 1; //cin >> t;
    while(t--) solve();
}

컴파일 시 표준 에러 (stderr) 메시지

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