Submission #4555959


Source Code Expand

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/12  Problem: ABC 085 D / Link: http://abc085.contest.atcoder.jp/tasks/abc085_d  ----- */


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

	LL N, H; cin >> N >> H;
	vector<LL> a(N), b(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i] >> b[i];
	}

	LL ans = 0LL;
	vector<PLL>x;
	FOR(i, 0, N) {
		x.push_back(PLL(a[i], 0));
		x.push_back(PLL(b[i], 1));
	}
	RSORT(x);
	for (auto it : x) {
		if (H <= 0)break;
		if (it.second) {
			H -= it.first;
			ans++;
		}
		else {
			LL k = (H - 1 + it.first) / it.first;
			ans += k;
			H -= k * it.first;
		}
	}
	
	
	cout << (ans) << "\n";

	return 0;
}

Submission Info

Submission Time
Task D - Katana Thrower
User Yang33
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1623 Byte
Status AC
Exec Time 36 ms
Memory 7792 KiB

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 KiB
a02 AC 1 ms 256 KiB
a03 AC 1 ms 256 KiB
a04 AC 1 ms 256 KiB
b05 AC 1 ms 256 KiB
b06 AC 30 ms 6640 KiB
b07 AC 1 ms 256 KiB
b08 AC 30 ms 7792 KiB
b09 AC 1 ms 256 KiB
b10 AC 1 ms 256 KiB
b11 AC 1 ms 256 KiB
b12 AC 1 ms 256 KiB
b13 AC 21 ms 7536 KiB
b14 AC 20 ms 6640 KiB
b15 AC 20 ms 6128 KiB
b16 AC 21 ms 7152 KiB
b17 AC 36 ms 7408 KiB
b18 AC 32 ms 6128 KiB
b19 AC 27 ms 6640 KiB
b20 AC 29 ms 6512 KiB
b21 AC 32 ms 6896 KiB
b22 AC 33 ms 7792 KiB
b23 AC 1 ms 256 KiB
b24 AC 2 ms 512 KiB