제출 #537254

#제출 시각아이디문제언어결과실행 시간메모리
537254theysoldtheworldArt Exhibition (JOI18_art)C++14
100 / 100
188 ms12052 KiB
#include <bits/stdc++.h>
 
using namespace std;

const long long inf = (long long)1e18;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<long long , long long>> a(n);
  for (int i = 0 ; i < n ; i++) {
    cin >> a[i].first >> a[i].second;
  }         
  sort(a.rbegin() , a.rend());
  vector<long long> dp(n);
  long long ans = 0;
  for (int i = 0 ; i < n ; i++) {
    dp[i] = a[i].second - a[i].first;
    if (i > 0) dp[i] = max(dp[i] , dp[i - 1] + a[i].second);
    ans = max(ans , dp[i] + a[i].first);
  }
  cout << ans << '\n';
  return 0; 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...