結果
| 問題 |
No.156 キャンディー・ボックス
|
| コンテスト | |
| ユーザー |
tokizo
|
| 提出日時 | 2018-01-13 00:17:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 168 ms / 2,000 ms |
| コード長 | 842 bytes |
| コンパイル時間 | 758 ms |
| コンパイル使用メモリ | 77,288 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 16:11:10 |
| 合計ジャッジ時間 | 2,044 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:35:18: warning: 'idx' may be used uninitialized [-Wmaybe-uninitialized]
35 | C[idx]--;
| ~~~~~^
main.cpp:28:17: note: 'idx' was declared here
28 | int idx, mi = INT_MAX;
| ^~~
ソースコード
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <typeinfo>
#include <climits>
#include <ctype.h>
#include <string>
using namespace std;
#define INIT cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
int main()
{
INIT;
int n, m;
cin >> n >> m;
int C[n];
REP(i, n) cin >> C[i];
int cnt = 0;
while(1){
if(m == 0) break;
else{
int idx, mi = INT_MAX;
REP(i, n){
if(mi > C[i] and C[i] != 0){
mi = C[i];
idx = i;
}
}
C[idx]--;
m--;
if(C[idx] == 0) cnt++;
}
}
cout << cnt << endl;
return 0;
}
tokizo