답안 #138002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
138002 2019-07-28T20:48:38 Z beso123 학교 설립 (IZhO13_school) C++14
5 / 100
2000 ms 20216 KB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define x first
#define y second
using namespace std;
int n,s,m,ans,rm,rs;
set <pii> sp,ms;
main(){
cin>>n>>s>>m;
for(int k=1;k<=n;k++){
    int a,b;
    cin>>a>>b;
    if(rm==0 && rs==0){
        if(a>b){
            rs++;
        sp.insert({a,b});
        ans=a;
        }
        else{
            rm++;
            ms.insert({b,a});
            ans=b;
        }
    }
    else{
     pii a1=*sp.begin(),b1=*ms.begin();
     if(a1.x<a)
        if(b1.x>=b){
                  if(rs==s){
                sp.erase(sp.begin());
            sp.insert({a,b});
            ans-=a1.x;
            ans+=a;
                    }
                    else{
                        sp.insert({a,b});
                        ans+=a;
                        rs++;
                    }
                    continue;
        }
           if(b1.x<b)
        if(a1.x>=a){
                if(rm==m){
                ms.erase(ms.begin());
            ms.insert({b,a});
            ans-=b1.x;
            ans+=b;
            }
            else{
             ms.insert({b,a});
             rm++;
             ans+=b;
            }
            continue;
        }
            int cnt1=ans,cnt2=ans;

            if(rs==s)
            cnt1=ans-a1.x+a;
            else cnt1=ans+a;

            if(rm==m)
            cnt2=ans-b1.x+b;
            else cnt2=ans+b;

            if(cnt1<ans && cnt2<ans)
                continue;

            if(cnt1>=cnt2){
                    if(rs==s){
                sp.erase(sp.begin());
            sp.insert({a,b});
            ans-=a1.x;
            ans+=a;
                if(rm!=m){
                ms.insert({a1.y,a1.x});
                ans+=a1.y;
                rm++;
                }
                else{
                    if(a1.y>b1.x){
                        ms.erase(ms.begin());
                        ms.insert({a1.y,a1.x});
                        ans-=b1.x;
                        ans+=a1.y;
                    }
                }
                }
                    else{
                        sp.insert({a,b});
                        ans+=a;
                        rs++;
                    }
            }
            else{
                    if(rm==m){
                ms.erase(ms.begin());
            ms.insert({b,a});
            ans-=b1.x;
            ans+=b;
            }
            else{
             ms.insert({b,a});
             rm++;
             ans+=b;
            }
                if(rs!=s){
                sp.insert({b1.y,b1.x});
                rs++;
                ans+=b1.y;
                }
                else{
                    if(b1.y>a1.x){
                        sp.erase(ms.begin());
                        sp.insert({b1.y,b1.x});
                        ans-=a1.x;
                        ans+=b1.y;
                    }
                }
            }
    }
    }
cout<<ans;
return 0;
}

Compilation message

school.cpp:9:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Execution timed out 2053 ms 376 KB Time limit exceeded
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Incorrect 2 ms 376 KB Output isn't correct
6 Incorrect 2 ms 256 KB Output isn't correct
7 Incorrect 7 ms 504 KB Output isn't correct
8 Incorrect 8 ms 632 KB Output isn't correct
9 Incorrect 8 ms 632 KB Output isn't correct
10 Incorrect 9 ms 632 KB Output isn't correct
11 Incorrect 8 ms 632 KB Output isn't correct
12 Incorrect 8 ms 632 KB Output isn't correct
13 Incorrect 53 ms 2424 KB Output isn't correct
14 Incorrect 92 ms 2040 KB Output isn't correct
15 Runtime error 18 ms 1400 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Incorrect 311 ms 11100 KB Output isn't correct
17 Runtime error 352 ms 18032 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 319 ms 15352 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 253 ms 18552 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 276 ms 20216 KB Execution killed with signal 11 (could be triggered by violating memory limits)