제출 #1324245

#제출 시각아이디문제언어결과실행 시간메모리
1324245camil7Art Exhibition (JOI18_art)C++20
100 / 100
134 ms12232 KiB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define int long long
#define ull unsigned long long
#define lb lower_bound
#define ub upper_bound

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> vt = {{0, 0}};
    for (int i = 1; i <= n; i++){
        int a, b;
        cin >> a >> b;
        vt.push_back({a, b});
    }
    sort(vt.begin(), vt.end());
    int dp[n + 5];
    memset(dp, 0, sizeof(dp));
    dp[1] = vt[1].second;
    for (int i = 2; i <= n; i++){
        dp[i] = max({dp[i - 1] + vt[i].second - (vt[i].first - vt[i - 1].first), vt[i].second});
    }
    int x = 0;
    for (int i = 1; i <= n; i++)x = max(x, dp[i]);
    cout << x << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...