답안 #1050108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050108 2024-08-09T07:28:03 Z vjudge1 Art Exhibition (JOI18_art) C++
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>

using namespace std;
//abeke

typedef long long ll;
typedef unsigned long long ull;

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define speed ios::sync_with_stdio( false); cin.tie(nullptr); cout.tie(0);
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define eb emplace_back
#define nl '\n'
#define f first
#define s second
#define gcd __gcd
#define ins insert
#define pii pair<ll, ll>
const int inf = INT_MAX;
const int mod = 1e9+7;
const int N = 2e5+5;
bool cmp(pii x, pii y) {
    return x.f > y.f;
}
void solve() {
    int n;
    cin >> n;
    vector<pii> a(n);
    forn (i, n) {
        cin >> a[i].f >> a[i].s;
    } sort(all(a));
    ll dp[n+2]{}, df[n+2]{};
    dp[1] = a[0].s+a[1].s-a[1].f+a[0].f;
    df[1] = 0;
    ll ans = dp[1];
    for (int i = 2; i < n; i++) {
        dp[i] = dp[i-1]-(a[i].f-a[i-1].f)+a[i].s;
        df[i] = df[i-1]-(a[i].f-a[i-1].f)+a[i].s;
        if (dp[i] < df[i]) {
            dp[i] = df[i];
        } else {
            df[i] = dp[i];
        }
        ans = max(ans, dp[i]);
    } cout << ans << nl;
}
int main()
{
    speed;
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -