Submission #00764


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<bits/stdc++.h>
using namespace std;
int N, Y, L[10000];
int Hitumabushi, ALL, MAX;
pair< bool, int > Check(int value, int x)
{
if(value == 0) return(make_pair(true, 0));
int ret = 0;
for(int i = 0; i < N; i++) {
ret += L[i] / value;
}
return(make_pair(ret >= x, ALL - min(x, ret) * value));
}
int BinarySearch(int lower, int upper, int x)
{
int mid = (lower + upper + 1) >> 1;
if(lower >= upper) return(lower);
else if(Check(mid, x).first) return(BinarySearch(mid, upper, x));
else return(BinarySearch(lower, mid - 1, x));
}
int main()
{
cin >> N;
for(int i = 0; i < N; i++) {
cin >> L[i];
}
ALL = accumulate(L, L + N, 0);
MAX = *max_element(L, L + N);
Hitumabushi = 1 << 30;
cin >> Y;
while(Y--) {
int M;
cin >> M;
int get = BinarySearch(0, MAX, M);
if(get == 0) cout << "NA" << endl;
else cout << get << endl;
Hitumabushi = min(Hitumabushi, Check(get, M).second);
}
cout << Hitumabushi << endl;
}

ステータス

項目 データ
問題 0045 - 浜名湖鰻と見習い料理人
ユーザー名 root
投稿日時 2015-07-16 23:25:07
言語 C++11
状態 Accepted
得点 1
ソースコード長 1024 Byte
最大実行時間 353 ms
最大メモリ使用量 623 KB

セット

セット 得点 Cases
1 ALL 20 / 20 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
HamanakoInput1.txt AC 18 ms 488 KB
1
HamanakoInput2.txt AC 14 ms 588 KB
1
HamanakoInput3.txt AC 13 ms 552 KB
1
HamanakoInput4.txt AC 13 ms 516 KB
1
HamanakoInput5.txt AC 98 ms 585 KB
1
HamanakoInput6.txt AC 13 ms 559 KB
1
HamanakoInput7.txt AC 151 ms 623 KB
1
HamanakoInput8.txt AC 156 ms 566 KB
1
HamanakoInput9.txt AC 207 ms 504 KB
1
HamanakoInputA.txt AC 353 ms 558 KB
1