제출 #972434

#제출 시각아이디문제언어결과실행 시간메모리
972434blackslexArt Exhibition (JOI18_art)C++17
100 / 100
153 ms24856 KiB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

int n;

int main() {
    scanf("%d", &n);
    vector<pii> a(n + 5);
    for (int i = 1; i <= n; i++) scanf("%lld %lld", &a[i].first, &a[i].second);
    sort(a.begin() + 1, a.begin() + n + 1);
    vector<ll> pref(n + 5);
    for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i].second;
    ll cmx = 0, ans;
    for (int i = 1; i <= n; i++) {
        cmx = max(cmx, a[i].first - pref[i - 1]);
        ans = max(ans, pref[i] - a[i].first + cmx);
    }
    printf("%lld", ans);
}

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

art.cpp: In function 'int main()':
art.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
art.cpp:12:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     for (int i = 1; i <= n; i++) scanf("%lld %lld", &a[i].first, &a[i].second);
      |                                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:16:17: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |     ll cmx = 0, ans;
      |                 ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...