Submission #163182

#TimeUsernameProblemLanguageResultExecution timeMemory
163182fenech20Art Exhibition (JOI18_art)C++14
100 / 100
391 ms20984 KiB
/**
 * Martin Leshko (leshko.martin@gmail.com)
 */

#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define sz(a) (int)a.size()

typedef long long ll;

int main() {
  ll n;
  scanf("%lld", &n);
  vector<pair<ll, ll> > a(n);
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", &a[i].first, &a[i].second);
  }
  sort(a.begin(), a.end());
  ll prefix = 0, ans = -0x3f33f3f3f3f3f, mn = 0x3f3f3f3f3f3f;
  for (int i = 0; i < n; i++) {
    mn = min(mn, prefix - a[i].first);
    prefix += a[i].second;
    ans = max(ans, prefix - mn - a[i].first);
//    fprintf(stderr, "mn = %d, prefix = %d, ans = %d\n", mn, prefix, ans);
  }
  printf("%lld", ans);
}

//

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &n);
   ~~~~~^~~~~~~~~~~~
art.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld", &a[i].first, &a[i].second);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...