Submission #966089

# Submission time Handle Problem Language Result Execution time Memory
966089 2024-04-19T11:15:38 Z MercubytheFirst Art Exhibition (JOI18_art) C++17
0 / 100
124 ms 262144 KB
#include <bits/stdc++.h>
using ll = long long;
#define pb push_back
using namespace std;
#define CDIV(a, b) ((((a) - (1)) / (b)) + 1)
const ll inf = 1e9 + 37;



template<typename T, size_t N>
std::ostream& operator<<(std::ostream& os, const std::array<T, N>& a);
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p);
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s);
template<typename T, typename cmp>
std::ostream& operator<<(std::ostream& os, const std::set<T, cmp>& s);



void solve() { 
  ll tempn;
  cin >> tempn;
  __int128_t n = tempn;
  vector<pair<__int128_t, __int128_t> > v(n + 1);
  vector<__int128_t> pref(n + 1);
  for(__int128_t i = 1; i <= n; ++i) {
    ll a, b;
    cin >> a >> b;
    v[i] = {a, b};
  }
  sort(v.begin() + 1, v.end());
  for(__int128_t i = 1; i <= n; ++i){
    pref[i] = pref[i - 1] + v[i].second;
  }
  // cout << v << endl << pref << endl;
  set<__int128_t> s{v[1].first};
  __int128_t ans = 0;
  for(__int128_t i = 1; i <= n; ++i) {
    ans = max(ans, -v[i].first + pref[i] + *s.rbegin());
    // cout << i << " : " << -v[i].first + pref[i] + *s.rbegin() << endl;
    if(i < n) {
      s.insert(-pref[i] + v[i + 1].first);
    }
  }
  cout << (ll)ans << endl;
}

signed main() {
  #ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // signed t = 0; cin >> t; while(t --> 0) 
    solve();
}

template<typename T, size_t N>
std::ostream& operator<<(std::ostream& os, const std::array<T, N>& a) {
  os << '[';
  for(size_t i = 0; i < N; ++i) {
    os << a[i] << " ";
  }
  os << "]";
  return os;
}

template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {
  os << "(" << p.first << ", " << p.second << ") ";
  return os;
}
 
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << '[';
  for(auto x : v)
    os << x << " ";
  os << "] ";
  return os;
}
 
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s) {
  os << "{";
  for(auto x : s)
    os << x << ", ";
  os << "} ";
  return os;
}
 
template<typename T, typename cmp>
std::ostream& operator<<(std::ostream& os, const std::set<T, cmp>& s) {
  os << "{";
  for(auto x : s)
    os << x << ", ";
  os << "} ";
  return os;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:53:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |   freopen("in.txt", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
art.cpp:54:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   freopen("out.txt", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 124 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 124 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 124 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 124 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -