Submission #1290566

#TimeUsernameProblemLanguageResultExecution timeMemory
1290566bilgetux38Art Exhibition (JOI18_art)C++20
0 / 100
1 ms572 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

int f(int l, int r, vector<pair<int,int>> &vec, vector<int> &pfx)
{
    return pfx[r+1] - pfx[l] - (vec[r].first -vec[l].first);
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n,  mxx = INT64_MIN;
    int l = 0;
    cin>>n;
    vector<pair<int,int>> vec(n);
    vector<int> pfx(n+1,0);
    for (int i = 0; i < n; ++i)
    {
        cin>>vec[i].first>>vec[i].second;
    }
    sort(vec.begin(),vec.end());
    for (int i = 0; i < n; ++i)
    {
        pfx[i+1] = pfx[i] + vec[i].second;
    }
    for (int r = 0; r < n; ++r)
    {
        while (l < r && f(l,r,vec,pfx) < f(l+1,r,vec,pfx))
            ++l;
        mxx = max(mxx, f(l, r, vec, pfx));
    }
    //mxx = max(mxx, f(l, r, vec, pfx)); geç artık :(
    
    cout<<mxx<<endl;
    return 0;

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...