Submission #966087

#TimeUsernameProblemLanguageResultExecution timeMemory
966087MercubytheFirstArt Exhibition (JOI18_art)C++17
0 / 100
289 ms143952 KiB
#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 n; cin >> n; vector<pair<ll, ll> > v(n + 1); vector<ll> pref(n + 1); for(ll i = 1; i <= n; ++i) { cin >> v[i].first >> v[i].second; } sort(v.begin() + 1, v.end()); for(ll i = 1; i <= n; ++i){ pref[i] = pref[i - 1] + v[i].second; } // cout << v << endl << pref << endl; set<ll> s{v[1].first}; ll ans = 0; for(ll 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 << 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 (stderr)

art.cpp: In function 'int main()':
art.cpp:50:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   freopen("in.txt", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
art.cpp:51:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |   freopen("out.txt", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...