Submission #1949489
Source Code Expand
/*
@@@@@@@@@@@@@@@@PP!!__......::ii@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@NNGG@@MM..............MM$$oo@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@UU--..::00@@II..........GGGG..^^NN@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@UU..........FF@@##,,......IINN....,,WW@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@WW..............--##NNll....++@@''....::NN@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@^^............--::JJ@@@@dd....NNrr......++@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@LL....--rrooqqDDNN@@@@@@@@@@WWcc00JJ........UU@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@EEGGWW@@NNDD@@@@@@@@@@@@@@@@@@@@@@VV......^^@@NN%%AANN@@@@@@@@@@##%%%%qq%%NN@@@@@@@@003333AAwwwwWW@@@@NNwwdd%%%%##@@@@@@DDSSddGGGGGGGGddWW@@@@ddGG@@@@@@@@UUAANN@@@@@@GGAAGGGGmmNN@@@@@@@@UUddGGGGGGGG
@@DDqqffrr..^^@@@@@@@@@@@@@@@@@@@@@@OO......NN@@''''..22@@@@@@@@WW............EE@@@@@@ll..........GG@@@@PP..........::NN@@::..............ee@@%%....NN@@@@NN....%%@@@@##............&&@@@@WW..........,,
ff..........QQ@@@@@@@@@@@@@@@@@@@@@@NN....RR@@;;..!!..))@@@@@@@@GG....$$##!!....NN@@@@,,..ff00####@@@@@@))..rrWWdd....77@@OOUUZZ....oo##AA@@@@JJ..!!@@@@@@AA....NN@@@@55..''88##--..!!@@@@AA....GG88GGWW
::........oo@@@@@@@@@@@@@@@@@@@@@@@@@@--==@@EE..!!qq..!!@@@@@@@@cc..//@@@@oo....NN@@MM....00@@@@@@@@@@@@,,..$$@@@@''..JJ@@@@@@OO..''@@@@@@@@@@!!..ss@@@@@@TT..;;@@@@@@ll..II@@@@rr..;;@@@@ll..rr@@@@@@@@
--......~~@@@@@@@@@@@@@@@@@@@@@@@@@@@@FF@@NN....NN@@..''NN@@@@@@,,..JJNNEE....++@@@@44....,,::::00@@@@MM....ooww;;..!!NN@@@@@@cc..rr@@@@@@@@NN....RR@@@@@@::..FF@@@@@@__..))SS//..,,QQ@@@@::....!!::11@@
........DD@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@;;..~~NN##....MM@@@@00....--......++NN@@@@ll....,,''::NN@@@@ZZ..'',,....nn@@@@@@@@@@::..**@@@@@@@@%%....NN@@@@00....##@@@@DD....::....((@@@@@@WW....''''..JJ@@
......SSUU))@@@@@@@@@@@@@@@@@@@@@@@@@@@@oo........''....GG@@@@SS....wwAAqqWW@@@@@@@@,,..SS@@@@@@@@@@@@cc..))NN!!..ii@@@@@@@@NN....UU@@@@@@@@aa..--@@@@@@SS....@@@@@@VV..,,NN))..^^@@@@@@qq..''@@@@@@@@@@
''..;;@@,,''@@@@@@@@@@@@@@@@@@@@@@@@@@QQ....11PP**FF,,..oo@@@@((..==@@@@@@@@@@@@@@MM....55NNMMWW@@@@@@__..55@@SS....NN@@@@@@dd....NN@@@@@@@@OO....oo00dd''..ss@@@@@@//..((@@00....##@@@@cc..!!NNNN00@@@@
!!..WWPP....NN@@@@@@@@@@@@@@@@@@@@@@@@::..;;@@@@@@@@//..++@@@@''..**@@@@@@@@@@@@@@ee..........!!@@@@##....QQ@@00....GG@@@@@@((..^^@@@@@@@@@@@@ii..........((@@@@@@NN....44@@@@''..LL@@@@__..........AA@@
CCee00......OO@@@@@@@@@@@@@@@@@@@@@@NNGGqq@@@@@@@@@@0055UU@@@@RRAANN@@@@@@@@@@@@@@MMaawwaaaaFFMM@@@@NNPPdd@@@@@@RRVV00@@@@@@UUZZDD@@@@@@@@@@@@@@UU2211oo##@@@@@@@@@@AA55NN@@@@88PP##@@@@qqZZeeFFoo55@@@@
@@NN::......aa@@@@@@@@@@@@@@@@@@@@@@@@@@@@QQ**ee@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@NN@@@@@@@@@@@@@@NN@@@@@@@@@@NNNN@@@@@@@@@@@@@@@@@@@@NNNNNN@@@@@@@@@@@@@@@@@@@@@@NNNN@@@@@@@@@@@@@@@@NNNN@@@@@@@@@@@@@@@@
@@EE........ssUU^^WW@@@@@@@@@@NNmmee((::......aa@@@@NN22NN@@@@@@@@WWccNN@@@@@@VVddooqq@@@@@@SSddAA%%@@@@@@ooqqZZdd@@@@@@@@LLOO@@@@@@GGccFFNN@@@@OOVV$$PP@@@@@@5544AAFF@@@@QQAA@@@@&&LLGGOO@@@@%%55dd%%@@
@@NN........;;WW....ww@@@@((................;;@@@@@@@@LL@@@@@@@@@@aa~~55@@@@@@**%%CC22@@@@OO**@@@@IIWW@@NNssUUoooo@@@@@@%%//11@@@@@@@@ee00@@@@@@ff@@@@EESS@@@@**GGRRiiNN@@##aa@@@@qqLLMMWW@@@@GGFF&&UU@@
@@@@UU......--NN!!....++NNOO''..............WW@@@@@@@@))00@@@@@@00//ddccMM@@@@LLddSS**@@@@8822@@@@ffNN@@NNII##PPaa@@@@@@//AAiiRR@@@@@@CC##@@@@@@iiNN@@ooRR@@@@22ddRRff@@@@##22@@@@3377##MM@@@@OODDSSii@@
@@@@@@qq......MM((......--UU@@**..........##@@@@@@@@@@FFeemm@@@@##%%@@UU88@@@@33GGGGRR@@@@@@44qqwwRR@@@@@@OO@@@@GG@@@@WWEE@@WWdd@@@@@@%%NN@@@@@@OOPP%%EE@@@@@@$$@@@@RRNN@@NNRR@@@@##ZZmm$$@@@@UUddmmSS@@
@@@@@@@@QQ::..qqPP..........11@@MM__..::00@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@NNNN@@@@
@@@@@@@@@@@@**GG%%..............DDNNGG@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@NNcc::......::==GG@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
/** Interface */
inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );
/** Read */
static const int buf_size = 4096;
inline int getChar() {
static char buf[buf_size];
static int len = 0, pos = 0;
if (pos == len) {
pos = 0, len = fread(buf, 1, buf_size, stdin);
}
if (pos == len) {
return -1;
}
return buf[pos++];
}
inline int readChar() {
int c = getChar();
while (c <= 32) {
c = getChar();
}
return c;
}
template <class T>
inline T readInt() {
int s = 1, c = readChar();
T x = 0;
if (c == '-')
s = -1, c = getChar();
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
return s == 1 ? x : -x;
}
/** Write */
static int write_pos = 0;
static char write_buf[buf_size];
inline void writeChar( int x ) {
if (write_pos == buf_size)
fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
write_buf[write_pos++] = x;
}
template <class T>
inline void writeInt( T x, char end ) {
if (x < 0)
writeChar('-'), x = -x;
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
if (end)
writeChar(end);
}
inline void writeWord( const char *s ) { while (*s)
writeChar(*s++); }
struct Flusher {
~Flusher() {
if (write_pos)
fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
}
} flusher;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
const string FILENAME = "input";
const int MAXN = 100001;
int a[MAXN], b[MAXN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//read(FILENAME);
int n, h;
cin >> n >> h;
vector<pair<int, int> > st;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
st.push_back(make_pair(a[i], -b[i]));
}
sort(all(st));
int f = st.back().first;
vector<int> kek, kek1;
for (int i = 0; i < n - 1; i++) {
if (-st[i].second > f) {
kek.push_back(-st[i].second);
}
kek1.push_back(-st[i].second);
}
sort(all(kek));
sort(all(kek1));
if (-st.back().second > f) {
int cnt1 = 0;
int h1 = h;
while (!kek1.empty()) {
if (h1 <= 0) {
break;
}
cnt1++;
h1 -= kek1.back();
kek1.pop_back();
}
int ans = 2e9;
if (h1 <= 0) {
chkmin(ans, cnt1);
}
int cnt = 0;
chkmin(ans, 1 + (max(0, h + st.back().second) + f - 1) / f);
while (!kek.empty()) {
if (h <= 0) {
break;
}
cnt++;
h -= kek.back();
kek.pop_back();
if (h <= 0) {
chkmin(ans, cnt);
}
chkmin(ans, cnt + 1 + (max(0, h + st.back().second) + f - 1) / f);
}
cout << ans << endl;
} else {
reverse(all(kek));
int cnt = 0;
for (auto x: kek) {
if (h <= 0) {
break;
}
cnt++;
h -= x;
}
if (h > 0) {
cnt += (h + f - 1) / f;
}
cout << cnt << endl;
}
}
Submission Info
Submission Time |
|
Task |
D - Katana Thrower |
User |
EgorLifar |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
9792 Byte |
Status |
AC |
Exec Time |
35 ms |
Memory |
3316 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
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 |
27 ms |
2676 KB |
b07 |
AC |
1 ms |
256 KB |
b08 |
AC |
27 ms |
2676 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 |
20 ms |
3060 KB |
b14 |
AC |
19 ms |
3060 KB |
b15 |
AC |
17 ms |
2676 KB |
b16 |
AC |
17 ms |
2676 KB |
b17 |
AC |
32 ms |
2676 KB |
b18 |
AC |
29 ms |
2676 KB |
b19 |
AC |
26 ms |
3060 KB |
b20 |
AC |
27 ms |
3188 KB |
b21 |
AC |
35 ms |
3316 KB |
b22 |
AC |
35 ms |
3060 KB |
b23 |
AC |
1 ms |
256 KB |
b24 |
AC |
2 ms |
384 KB |