Submission #751276

#TimeUsernameProblemLanguageResultExecution timeMemory
751276aufanArt Exhibition (JOI18_art)C++17
100 / 100
202 ms13900 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second #define all(x) (x).begin(), (x).end() using namespace std; const int INFF = 1e18; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<pair<int, int>> v(n); for (int i = 0; i < n; i++) cin >> v[i].fi >> v[i].se; sort(all(v)); /* 1 3 3 2 5 1 2 1 1 3 1 0 6 3 0 7 4 3 8 5 4 100 9 dp[i] = max(dp[i], dp[j] - (w[i] - w[j]) + b[i]) dp[i] = max(dp[i], dp[j] - w[i] + w[j] + b[i]) dp[i] = max(dp[i], dp[j] + w[j]) + b[i] - w[i] */ vector<int> dp(n, 0ll); dp[0] = v[0].se; int mx = dp[0] + v[0].fi; for (int i = 1; i < n; i++) { dp[i] = max(v[i].se, mx + v[i].se - v[i].fi); mx = max(mx, dp[i] + v[i].fi); } cout << *max_element(all(dp)) << '\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...