Submission #1952607


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
#define rep(var,n)  for(int var=0;var<(n);++var)
#define ALL(c)  (c).begin(),(c).end()


ll solve(int N, ll H, vi& a, vi& b) {
    int best = 0x7fffffff;

    vector<int> z(ALL(b));
    sort(ALL(z)); reverse(ALL(z));

    vector<ll> ac(N+1, 0);
    rep(i,N) ac[i+1] = ac[i] + z[i]; // どこかでHを超えるかも

    int ai = *max_element(ALL(a));
    rep(i, N+1) {
        ll rem = H - ac[i];
        if (rem > 0) {
            int pls = (rem + ai - 1) / ai;
            best = min(best, i + pls);
        } else {
            best = min(best, i);
        }
    }
    return best;
}

int main() {
    int N, H; cin >> N >> H;
    vector<int> a(N), b(N);
    rep(i, N){
        cin >> a[i] >> b[i];
    }
    cout << solve(N, H, a, b) << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Katana Thrower
User naoya_t
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1021 Byte
Status AC
Exec Time 92 ms
Memory 2176 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 24
Set Name Test Cases
Sample a01, a02, a03, a04
All a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
a04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 89 ms 2176 KB
b07 AC 1 ms 256 KB
b08 AC 92 ms 2176 KB
b09 AC 1 ms 256 KB
b10 AC 1 ms 256 KB
b11 AC 1 ms 256 KB
b12 AC 1 ms 256 KB
b13 AC 35 ms 2176 KB
b14 AC 35 ms 2176 KB
b15 AC 34 ms 2176 KB
b16 AC 36 ms 2176 KB
b17 AC 57 ms 2176 KB
b18 AC 50 ms 2176 KB
b19 AC 42 ms 2176 KB
b20 AC 46 ms 2176 KB
b21 AC 54 ms 2176 KB
b22 AC 56 ms 2176 KB
b23 AC 1 ms 256 KB
b24 AC 3 ms 256 KB