Submission #880195

# Submission time Handle Problem Language Result Execution time Memory
880195 2023-11-29T02:48:06 Z niter Art Exhibition (JOI18_art) C++14
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
#define loop(i,a,b) for(int i = (a); i < (b); i ++)
#define pb push_back
#define ins insert
#define pii pair<int,int>
#define ff first
#define ss second
#define op(x) cerr << #x << " = " << x << endl;
#define opa(x) cerr << #x << " = " << x << ", ";
#define ops(x) cerr << x;
#define entr cerr << endl;
#define spac cerr << ' ';
#define STL(x) cerr << #x << " : "; for(auto &qwe:x) cerr << qwe << ' '; cerr << endl;
#define ARR(x, nnn) cerr << #x <<  " : "; loop(qwe,0,nnn) cerr << x[qwe] << ' '; cerr << endl;
#define BAE(x) x.begin(), x.end()
#define unilize(x) x.resize(unique(BAE(x)) - x.begin())
#define unisort(x) sort(BAE(x)); unilize(x);
using namespace std;
typedef long long ll;

struct P{
    ll A, B;
    bool operator<(P x){
        return (A == x.A) ? (B < x.B) : (A < x.A);
    }
};
const int mxn = (int)(1e5) + 10;
P x[mxn];

int main(){
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    ll ans = 0;
    loop(i,1,n+1){
        cin >> x[i].A >> x[i].B;
    }
    x[0].A = x[0].B = 0;
    sort(x + 1, x + n + 1);
    ll sum_B = 0, A_min = x[0].A;
    for(int i = 1, j = 1; i <= n; i++){
        sum_B += x[i].B;
        while(j < n && j < i){
            if(sum_B - x[j].B + x[j+1].A >= sum_B + x[j].A){
                sum_B -= x[j].B;
                j++;
            }
            else break;
        }
//        opa(i) op(j) op(sum_B)
        ans = max(ans, sum_B - x[i].A + x[j].A);
    }
    cout << ans;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:40:19: warning: unused variable 'A_min' [-Wunused-variable]
   40 |     ll sum_B = 0, A_min = x[0].A;
      |                   ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -