Submission #503379

# Submission time Handle Problem Language Result Execution time Memory
503379 2022-01-07T18:39:50 Z lukameladze Schools (IZhO13_school) C++14
75 / 100
2000 ms 19752 KB
# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define int long long
#define pii pair <int, int> 
using namespace std;
const int N = 3e5 + 5;
int n,m,k,a[N],b[N],sum,num,ans,pr[N],sf[N];
multiset <int> ms;
multiset <int> :: iterator it;
vector <pii> v;
main() {
    std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>n>>m>>k;
    for (int i = 1; i <= n; i++) {
        cin>>a[i]>>b[i];
        v.pb({a[i] - b[i], i});
    }
    sort(v.begin(),v.end()); reverse(v.begin(),v.end());
    for (int i = 0; i < v.size(); i++) {
        num = a[v[i].s];
        if (ms.size() < m) {
            ms.insert(num);
            sum += num;
        }
        else {
            it = ms.begin();
            if (*it < num) {
                sum -= *it;
                ms.erase(it); 
                sum += num; ms.insert(num);
            }
        } pr[i] = sum;
    } sum = 0;
    ms.clear();
    for (int i = (int)v.size() - 1; i >= 0; i--) {
        num = b[v[i].s];
        
        if (ms.size() < k) {
            ms.insert(num); sum += num;
        } else {
            it = ms.begin();
            if (*it < num) {
                sum -= *it;
                ms.erase(it); sum += num; ms.insert(num);
            }
        }
        sf[i] = sum;
    }
    for (int i = m; i <= n - k; i++) {
        ans = max(ans, pr[i] + sf[i + 1]);
    }
    cout<<ans<<endl;
}

Compilation message

school.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main() {
      | ^~~~
school.cpp: In function 'int main()':
school.cpp:21:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
school.cpp:23:23: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   23 |         if (ms.size() < m) {
      |             ~~~~~~~~~~^~~
school.cpp:40:23: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   40 |         if (ms.size() < k) {
      |             ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Execution timed out 2071 ms 332 KB Time limit exceeded
3 Incorrect 0 ms 332 KB Output isn't correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Incorrect 2 ms 716 KB Output isn't correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 16 ms 3528 KB Output is correct
14 Correct 30 ms 5040 KB Output is correct
15 Correct 46 ms 8032 KB Output is correct
16 Incorrect 127 ms 16076 KB Output isn't correct
17 Correct 142 ms 15512 KB Output is correct
18 Correct 142 ms 15960 KB Output is correct
19 Correct 162 ms 17296 KB Output is correct
20 Correct 194 ms 19752 KB Output is correct