Submission #725296

#TimeUsernameProblemLanguageResultExecution timeMemory
725296fdnfksdSchools (IZhO13_school)C++14
100 / 100
136 ms19344 KiB
#include <bits/stdc++.h>
#define pb push_back
#define vii vector<int>
#define pll pair<ll, ll>
#define pii pair< ll, pair< ll, ll > >
#define fi first
#define se second
#define int ll
using ll = long long;
using ld = long double;
using ull = unsigned long long;
const ll mod = 1e18+7;
using namespace std;
const ll N = 4e5;
ll tong, m, n, k, ans=mod, p, t, b[N], c[N], a[N], rb[N], ra[N], lab[N];
pll d[N*3];
//bool check;
string s;
vector<ll> kq, pre;
priority_queue< ll > pb, pa;

void sol()
{
    cin >> k >> n >> m;
    p=k-n-m;
    for(int i = 1 ; i <= k ;i ++)
    {

        cin >> a[i] >> b[i] ;
        a[i]*=-1;
        b[i]*=-1;
        c[i]=0;
        d[i].se = i;
        d[i].fi = a[i] - b[i];
        tong += c[i];
    }
    sort(d+1, d+1+k,greater<pair<int,int>>());
    for(int i = 1; i <= k; i ++)
    {
        pb.push(b[d[i].se] - c[d[i].se]);
        rb[i] = rb[i-1] + b[d[i].se] - c[d[i].se];
        while(pb.size() > m)
        {
            rb[i] -= pb.top();
            pb.pop();
        }
    }
    for(int i = k; i > 0; i --)
    {
        pa.push(a[d[i].se] - c[d[i].se]);
        ra[i] = ra[i+1] + a[d[i].se] - c[d[i].se];
        while(pa.size() > n)
        {
            ra[i] -= pa.top();
            pa.pop();
        }
    }
    for(int i = m; i <= k - n; i ++)
    {
        ans = min(ans, tong + ra[i+1] + rb[i]);
    }
    cout << -ans;
}

signed main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest;
    ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}

Compilation message (stderr)

school.cpp: In function 'void sol()':
school.cpp:42:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   42 |         while(pb.size() > m)
      |                         ^
school.cpp:52:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   52 |         while(pa.size() > n)
      |               ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...