답안 #683000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683000 2023-01-17T13:17:33 Z smartmonky 학교 설립 (IZhO13_school) C++14
95 / 100
178 ms 18556 KB
#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long

using namespace std;

const int  N = (int)3e5+7;

int p[N], p2[N];
bool comp(pair <int,int> a, pair <int,int> b){
    return a.ff - a.ss > b.ff - b.ss;
}
main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, s;
    cin >> n >> m >> s;
    vector <pair <int,int> > vp(n);
    for(int i = 0; i < n; i++){
        cin >> vp[i].ff >> vp[i].ss;
    }
    sort(all(vp), comp);
    multiset <int> st;
    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += vp[i].ff;
        st.insert(vp[i].ff);
        if(st.size() > m){
            sum -= *(st.begin());
            st.erase(st.begin());
        }
        p[i] = sum;
    }
    st.clear();
    sum = 0;
     for(int i = n - 1; i >= 1; i--){
        sum += vp[i].ss;
        st.insert(vp[i].ss);
        if(st.size() > s){
            sum -= *(st.begin());
            st.erase(st.begin());
        }
        p2[i] = sum;
    }
    int ans = 0;
    for(int i = 0; i < n - 1; i++){
        ans = max(ans, p[i] + p2[i + 1]);
    }
    cout << ans;
}

Compilation message

school.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main(){
      | ^~~~
school.cpp: In function 'int main()':
school.cpp:33:22: 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]
   33 |         if(st.size() > m){
      |            ~~~~~~~~~~^~~
school.cpp:44:22: 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]
   44 |         if(st.size() > s){
      |            ~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 4 ms 668 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 3 ms 720 KB Output is correct
13 Correct 17 ms 3280 KB Output is correct
14 Correct 37 ms 4712 KB Output is correct
15 Correct 61 ms 7372 KB Output is correct
16 Correct 114 ms 15308 KB Output is correct
17 Correct 135 ms 14600 KB Output is correct
18 Correct 140 ms 14964 KB Output is correct
19 Correct 177 ms 16156 KB Output is correct
20 Correct 178 ms 18556 KB Output is correct