답안 #967672

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967672 2024-04-22T15:44:24 Z njoop Art Exhibition (JOI18_art) C++14
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll n, l=1, r=1, sum, ans;
pair<ll, ll> arr[100010];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> arr[i].first >> arr[i].second;
    }
    sort(arr+1, arr+n+1);
    sum = arr[1].second;
    ans = max(ans, sum);
    while(r <= n) {
        while(l < r && arr[l].second <= arr[l+1].first-arr[l].first) {
            sum += arr[l+1].first-arr[l].first-arr[l].second;
            l++;
        }
        ans = max(ans, sum);
        if(r == n) break;
        r++;
        sum += arr[r].second - arr[r].first + arr[r-1].first;
        if(sum <= 0) {
            l = r+1;
            r++;
            sum = arr[r].second;
        }
        ans = max(ans, sum);
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -