Submission #84459

# Submission time Handle Problem Language Result Execution time Memory
84459 2018-11-15T08:45:09 Z talip Schools (IZhO13_school) C++14
100 / 100
179 ms 9364 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, m, q, a[N], b[N], p[N];
long long int f[N], g[N], s, res;
 //Memory leak with vector......
 //Will test against greater<int>
bool fark(int x, int y) {
    return a[x] - b[x] < a[y] - b[y];
}
 
int main() {
    ios::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i){
    	cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; ++i){
    	p[i] = i;
    }
    sort(p, p + n, fark);    priority_queue<int> pq;	s = 0;
    for(int i = 0; i < n; ++i) {
        pq.push(-b[p[i]]); s += b[p[i]];
        if (pq.size()>q) {
            s += pq.top(); pq.pop();
        }
        f[i] = s;
    }
    while(pq.size()){
    	pq.pop();
    }
    s = 0;
    for(int i=n-1;i>=0;i--){
        pq.push(-a[p[i]]); s += a[p[i]];
        if (pq.size()>m) {
            s+=pq.top();	pq.pop();
        }
        g[i] = s;
    }
    for (int i = q - 1; i < n - m; ++i){
    	res = max(res, f[i] + g[i + 1]);
    }
    cout << res;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:24:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (pq.size()>q) {
             ~~~~~~~~~^~
school.cpp:35:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (pq.size()>m) {
             ~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 4 ms 740 KB Output is correct
8 Correct 4 ms 740 KB Output is correct
9 Correct 4 ms 740 KB Output is correct
10 Correct 4 ms 740 KB Output is correct
11 Correct 4 ms 808 KB Output is correct
12 Correct 4 ms 808 KB Output is correct
13 Correct 20 ms 1720 KB Output is correct
14 Correct 46 ms 2872 KB Output is correct
15 Correct 83 ms 4924 KB Output is correct
16 Correct 148 ms 6400 KB Output is correct
17 Correct 131 ms 7132 KB Output is correct
18 Correct 137 ms 7728 KB Output is correct
19 Correct 164 ms 8152 KB Output is correct
20 Correct 179 ms 9364 KB Output is correct