Submission #6975877


Source Code Expand

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 60;
constexpr auto mod = 1000000007;
constexpr auto MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    ll h;
    cin >> n >> h;
    ll a, b;
    vector<pair<ll, char>> k(2 * n);
    FOR(i, 0, n) {
        cin >> a >> b;
        k[2 * i] = { a,'a' };
        k[2 * i + 1] = { b,'b' };
    }

    rSORT(k, [](auto a, auto b) {return a.first > b.first; });
    ll ans = 0;
    int itr = 0;
    while (h > 0) {
        if (k[itr].second == 'a') {
            ans += h / k[itr].first + (bool)(h % k[itr].first);
            h = 0;
        }
        else {
            ans++;
            h -= k[itr++].first;
        }
    }

    cout << ans << "\n";
}

Submission Info

Submission Time
Task D - Katana Thrower
User first_vil
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1421 Byte
Status AC
Exec Time 29 ms
Memory 3328 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 26 ms 3328 KB
b07 AC 1 ms 256 KB
b08 AC 25 ms 3328 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 16 ms 3328 KB
b14 AC 16 ms 3328 KB
b15 AC 16 ms 3328 KB
b16 AC 19 ms 3328 KB
b17 AC 29 ms 3328 KB
b18 AC 25 ms 3328 KB
b19 AC 21 ms 3328 KB
b20 AC 23 ms 3328 KB
b21 AC 26 ms 3328 KB
b22 AC 27 ms 3328 KB
b23 AC 1 ms 256 KB
b24 AC 2 ms 384 KB