Submission #49680

# Submission time Handle Problem Language Result Execution time Memory
49680 2018-06-02T05:28:34 Z mra2322001 Schools (IZhO13_school) C++14
0 / 100
2 ms 608 KB
#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i<(n); i++)
#define f1(i, n) for(int i(1); i<=(n); i++)

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
const int N = 300002;

int n, s, t;
long t1[N], t2[N];
pii a[N];

istream& operator >> (istream &is, pii &iu){
    cin >> iu.first >> iu.second;
}

int main(){
    ios_base::sync_with_stdio(0);

    cin >> n >> s >> t;
    f1(i, n) cin >> a[i];
    sort(a + 1, a + n + 1, [&](pii a1, pii a2){
         return (a1.second - a1.first) < (a2.second - a2.first);
    });
    priority_queue <int, vector <int>, greater <int> > q;
    f1(i, n){
        if(q.size() < s){
            t1[i] = t1[i - 1] + a[i].first;
            q.push(a[i].first);
        }
        else if(q.top() < a[i].first){
            t1[i] = t1[i - 1] - q.top() + a[i].first;
            q.pop();
            q.push(a[i].first);
        }
        else{
            t1[i] = t1[i - 1];
        }
    }
    while(q.size()) q.pop();
    for(int i = n; i >= 1; i--){
        if(q.size() < t){
            t2[i] = t2[i + 1] + a[i].second;
            q.push(a[i].second);
        }
        else if(q.top() < a[i].second){
            t2[i] = t2[i + 1] - q.top() + a[i].second;
            q.pop();
        }
        else{
            t2[i] = t2[i + 1];
        }
    }
    long res = 0;
    f1(i, n){
        res = max(res, t1[i] + t2[i + 1]);
    }
    cout << res;
}

Compilation message

school.cpp: In function 'std::istream& operator>>(std::istream&, pii&)':
school.cpp:16:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
school.cpp: In function 'int main()':
school.cpp:28:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(q.size() < s){
            ~~~~~~~~~^~~
school.cpp:43:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(q.size() < t){
            ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Incorrect 2 ms 608 KB Output isn't correct
5 Halted 0 ms 0 KB -