Submission #171744

#TimeUsernameProblemLanguageResultExecution timeMemory
171744davitmargSchools (IZhO13_school)C++17
100 / 100
277 ms18556 KiB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 300005;

int n, m, k;
LL ans, pr[N], sf[N];
pair<LL, LL> a[N];
multiset<LL> s;
int main()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
        scanf("%lld%lld", &a[i].first, &a[i].second);
    sort(a + 1, a + 1 + n, [](pair<LL, LL> a, pair<LL, LL> b) {
        return a.first - a.second > b.first - b.second;
    });

    for (int i = 1; i <= n; i++)
    {
        pr[i] = pr[i - 1] + a[i].first;
        s.insert(a[i].first);
        if (s.size() > m)
        {
            pr[i] -= (*s.begin());
            s.erase(s.begin());
        }
    }
    s.clear();
    for (int i = n; i >= 1; i--)
    {
        sf[i] = sf[i + 1] + a[i].second;
        s.insert(a[i].second);
        if (s.size() > k)
        {
            sf[i] -= (*s.begin());
            s.erase(s.begin());
        }
    }

    for (int i = 1; i <= n; i++)
        ans = max(pr[i] + sf[i + 1], ans);
    cout << ans << endl;
    return 0;
}

/*
 
3 1 1
100 0
100 50
0 20
 
4 1 1
100 0
550 500
500 550
0 100
 
3 1 1
100 0
500 550
0 100
 
 
 
*/

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:45:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (s.size() > m)
             ~~~~~~~~~^~~
school.cpp:56:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (s.size() > k)
             ~~~~~~~~~^~~
school.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &a[i].first, &a[i].second);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...