Submission #5027820


Source Code Expand

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

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

	int n, h;
	cin >> n >> h;
	vector<int> a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];

	// 何を優先するか
	// もしaでbのマックス以上の値があればずっとそれをやる
	// a <= bだった
	// bとaの攻撃順番は実質変わらない
	// 大きい順にソートする

	sort(allof(a), greater<int>());
	sort(allof(b), greater<int>());

	// aは一番大きいものだけで充分
	int amax = a[0];
	// bを上から見てってamax以下となったらその後amax使う
	int i = 0;
	while (h > 0) {
		if (amax >= b[i]) break;
		h -= b[i];
		i++;
		if (i == n) break;
	}

	int ans = i;

	if (h > 0) {
		ans += h / amax;
		if (h % amax != 0) ans++;
	}

	cout << ans << endl;

	return 0;
}

Submission Info

Submission Time
Task D - Katana Thrower
User tada
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1687 Byte
Status AC
Exec Time 28 ms
Memory 1152 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 1024 KB
b07 AC 1 ms 256 KB
b08 AC 24 ms 1024 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 1024 KB
b14 AC 15 ms 1024 KB
b15 AC 15 ms 1024 KB
b16 AC 15 ms 1024 KB
b17 AC 28 ms 1024 KB
b18 AC 24 ms 1024 KB
b19 AC 20 ms 1024 KB
b20 AC 22 ms 1024 KB
b21 AC 25 ms 1152 KB
b22 AC 26 ms 1024 KB
b23 AC 1 ms 256 KB
b24 AC 2 ms 256 KB