제출 #1290547

#제출 시각아이디문제언어결과실행 시간메모리
1290547bilgetux38Art Exhibition (JOI18_art)C++20
0 / 100
1 ms332 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] - pfx[l-1] - (vec[r].first -vec[l].first);
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n,  mxx = 0;
    int l = 1, r = 1;
    cin>>n;
    vector<pair<int,int>> vec(n+1);
    vector<int> pfx(n+1,0);
    for (int i = 0; i < n; ++i)
    {
        cin>>vec[i+1].first>>vec[i+1].second;
    }
    sort(vec.begin()+1,vec.end());
    for (int i = 1; i <= n; ++i)
    {
        pfx[i] = pfx[i-1] + vec[i].second;
    }
    int i = 1;
    while (i <= n)
    {
        if (f(l,r,vec,pfx) < f(l,i,vec,pfx))
            r = i;
        while (f(l,r,vec,pfx) < f(l+1,r,vec,pfx))
            ++l;
        ++i;
    }
    
    
    cout<<f(l,r,vec,pfx)<<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...