답안 #967660

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

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

signed 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(true) {
        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 1 ms 344 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -