답안 #482092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482092 2021-10-23T04:26:11 Z Neos Hotel (CEOI11_hot) C++14
100 / 100
1146 ms 60804 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;

#define task "test"
#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i, l, r) for( ll i = (l) ; i < (r) ; i++ )
#define forb(i, r, l) for( ll i = (r) ; i >= (l) ; i-- )
#define numBit(x) (__builtin_popcountll(1ll * (x)))
#define getBit(x, i) ((x) >> (i) & 1)
#define sz(x) (int)x.size()
#define mp make_pair
#define fi first
#define se second
#define ar array
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define debug(x) cerr << #x << " = " << x << '\n';

const int N = 5e5 + 7;
const ll inf = 0x3f3f3f3f;

template<typename T>
bool scan(T &num) {
  num = 0;
  register char c = getchar();
  while (c != '-' && (c < '0' || '9' < c)) {
      if (feof(stdin)) return false;
      c = getchar();
  }
  bool neg = false;
  if (c == '-') {
      neg = true;
      c = getchar();
  }
  for(; '0' <= c && c <= '9'; c = getchar()) num = (num << 1) + (num << 3) + (c - '0');
  if (neg) num = -num;
  return true;
}

int n, m, k;
ll res = 0;
ii c[N];
set<ar<int, 3>> rooms;
vi profit;

bool operator<(ar<int, 3> a, ar<int, 3> b) {
    return a[0] < b[0];
}

int main() {
    scan(n), scan(m), scan(k);
    forw(i, 0, n) {
        ar<int, 3> room;
        scan(room[1]), scan(room[0]), room[2] = i;
        rooms.insert(room);
    }
    forw(i, 0, m) scan(c[i].fi), scan(c[i].se);
    sort(c, c + m, greater<ii>());

    forw(i, 0, m) {
        auto it = rooms.lower_bound({c[i].se, 0, 0});
        if (it == rooms.end()) continue;

        int cur = c[i].fi - (*it)[1];
        if (cur > 0) {
            profit.pb(cur);
            rooms.erase(it);
        }
    }
    sort(all(profit), greater<int>());
    forw(i, 0, min(k, sz(profit))) res += profit[i];
    cout << res;
}

Compilation message

hot.cpp: In function 'int main()':
hot.cpp:24:12: warning: narrowing conversion of 'c[i].std::pair<long long int, long long int>::second' from 'long long int' to 'int' [-Wnarrowing]
   24 | #define se second
      |            ^
hot.cpp:76:43: note: in expansion of macro 'se'
   76 |         auto it = rooms.lower_bound({c[i].se, 0, 0});
      |                                           ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 3568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 6124 KB Output is correct
2 Correct 51 ms 7188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 17092 KB Output is correct
2 Correct 105 ms 13612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 708 ms 33716 KB Output is correct
2 Correct 783 ms 47172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 818 ms 41696 KB Output is correct
2 Correct 973 ms 60804 KB Output is correct
3 Correct 1146 ms 57944 KB Output is correct