답안 #117647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
117647 2019-06-17T03:48:24 Z JohnTitor Hotel (CEOI11_hot) C++11
100 / 100
1519 ms 48000 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define setbit(s, i) (s|=(1LL<<(i)))
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
using ll=long long;
using ld=long double;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "Hotel"
class room{
public:
    int c, p;
    void input(){
        read(c);
        read(p);
    }
} r[500000];
class order{
public:
    int v, d;
    void input(){
        read(v);
        read(d);
    }
} o[500000];
multiset <pair <int, int>> avail;
multiset <int> rented_reward;
int n, m, k;
int main(){
    #ifdef Uiharu
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Uiharu
    read(n);
    read(m);
    read(k);
    FFOR(i, 0, n) r[i].input();
    FFOR(i, 0, m) o[i].input();
    sort(r, r+n, [](room A, room B){
        return A.p>B.p;
    });
    sort(o, o+m, [](order A, order B){
        return (A.v>B.v);
    });
    FFOR(i, 0, n) avail.insert(mp(r[i].p, r[i].c));
    int j=0;
    FFOR(i, 0, m){
        auto it=avail.lower_bound(mp(o[i].d, 0));
        if(it==avail.end()) continue;
        rented_reward.insert(o[i].v-it->second);
        avail.erase(it);
    }
    ll ans=0;
    FOR(i, 1, k){
        ans+=max(0, *rented_reward.rbegin());
        rented_reward.erase(rented_reward.find(*rented_reward.rbegin()));
        if(rented_reward.empty()) break;
    }
    writeln(ans);
}

Compilation message

hot.cpp: In function 'int main()':
hot.cpp:79:9: warning: unused variable 'j' [-Wunused-variable]
     int j=0;
         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 4388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 7376 KB Output is correct
2 Correct 59 ms 6136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 435 ms 20600 KB Output is correct
2 Correct 141 ms 10616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 855 ms 40760 KB Output is correct
2 Correct 776 ms 40952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 716 ms 46968 KB Output is correct
2 Correct 1151 ms 33264 KB Output is correct
3 Correct 1519 ms 48000 KB Output is correct