Submission #72992

#TimeUsernameProblemLanguageResultExecution timeMemory
72992garyyeArt Exhibition (JOI18_art)C++14
100 / 100
357 ms8652 KiB
// author: gary
// created: 2018/08/27 14:14:01
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <limits>
#include <utility>
#include <functional>
#include <string>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;
#define SZ(x) ( (int) (x).size() )
#define ALL(c) (c).begin(), (c).end()
#define CNT(c, x) ((c).find(x) != (c).end())
typedef long long ll;
typedef pair<ll, int> pii;
template<class T> bool cmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool cmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }


const int N = 5e5 + 10;

int n;
pii p[N];

int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%lld%d", &p[i].first, &p[i].second);
  }
  sort(p, p + n);

  ll ans = -(1LL << 62);
  ll best = -(1LL << 62);

  ll sum = 0;
  for(int i = 0; i < n; i++) {
    ll nsum = sum + p[i].second;

    cmax(best, -sum + p[i].first);
    cmax(ans, nsum - p[i].first + best);

    sum = nsum;
  }

  printf("%lld\n", ans);
  return 0;
}

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
art.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%d", &p[i].first, &p[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...