Submission #259833

#TimeUsernameProblemLanguageResultExecution timeMemory
259833shivensinha4Art Exhibition (JOI18_art)C++17
0 / 100
4 ms1152 KiB
#include <bits/stdc++.h> using namespace std; #define for_(i, s, e) for (int i = s; i < e; i++) #define for__(i, s, e) for (ll i = s; i < e; i++) #define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str() typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; #define endl '\n' int main() { #ifndef ONLINE_JUDGE freopen("test.in", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<pair<ll, ll>> nums(n); // size, val for_(i, 0, n) cin >> nums[i].first >> nums[i].second; sort(nums.begin(), nums.end()); vector<ll> dp(n); dp[n-1] = nums[n-1].second - nums[n-1].first; for (int i = n-2; i >= 0; i--) { dp[i] = max(nums[i].second - nums[i].first, nums[i].second + dp[i+1]); } ll ans = 0; for_(i, 0, n) ans = max(ans, dp[i]+nums[i].first); cout << ans << endl; return 0; }

Compilation message (stderr)

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