답안 #503378

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503378 2022-01-07T18:36:52 Z lukameladze 학교 설립 (IZhO13_school) C++14
55 / 100
2000 ms 16184 KB
# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#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> s;
vector <pii> v;
main() {
    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 (s.size() < m) {
            s.insert(num);
            sum += num;
        }
        else {
            if (*(s.begin()) < num) {
                sum -= *(s.begin());
                s.erase(s.begin()); sum += num; s.insert(num);
            }
        } pr[i] = sum;
    } sum = 0;
    s.clear();
    for (int i = (int)v.size() - 1; i >= 0; i--) {
        num = b[v[i].s];
        
        if (s.size() < k) {
            s.insert(num); sum += num;
        } else {
            
            if (*(s.begin()) < num) {
                sum -= *(s.begin());
                s.erase(s.begin()); sum += num; s.insert(num);
            }
        }
        sf[i] = sum;
    }
    for (int i = m; i <= n - k; i++) {
        ans = max(ans, pr[i] + sf[i + 1]);
    //    cout<<i<<" "<<pr[i]<<" "<<sf[i + 1]<<endl;
    }
    cout<<ans<<endl;
}

Compilation message

school.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main() {
      | ^~~~
school.cpp: In function 'int main()':
school.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
school.cpp:20:22: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |         if (s.size() < m) {
      |                      ^
school.cpp:35:22: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |         if (s.size() < k) {
      |                      ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 300 KB Output isn't correct
2 Execution timed out 2070 ms 204 KB Time limit exceeded
3 Incorrect 0 ms 204 KB Output isn't correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 3 ms 444 KB Output is correct
8 Incorrect 4 ms 588 KB Output isn't correct
9 Correct 4 ms 564 KB Output is correct
10 Correct 5 ms 564 KB Output is correct
11 Correct 4 ms 564 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 29 ms 2924 KB Output is correct
14 Correct 54 ms 4020 KB Output is correct
15 Correct 95 ms 6028 KB Output is correct
16 Incorrect 173 ms 13924 KB Output isn't correct
17 Incorrect 208 ms 12992 KB Output isn't correct
18 Incorrect 227 ms 13132 KB Output isn't correct
19 Incorrect 244 ms 14228 KB Output isn't correct
20 Incorrect 279 ms 16184 KB Output isn't correct