結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
|
| 提出日時 | 2017-09-11 20:18:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 499 bytes |
| コンパイル時間 | 485 ms |
| コンパイル使用メモリ | 44,288 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-18 11:41:24 |
| 合計ジャッジ時間 | 1,489 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d", &L);
| ~~~~~^~~~~~~~~~
main.cpp:15:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
main.cpp:18:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
18 | scanf("%d", &t);
| ~~~~~^~~~~~~~~~
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <algorithm> //sort
#include <cstdlib>
using namespace std;
int main() {
int L, N;
vector<int> vc;
int t;
int ans = 0;
scanf("%d", &L);
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", &t);
vc.push_back(t);
}
sort(vc.begin(), vc.end());
for (int i = 0; i < N; i++) {
L -= vc.front();
if (L < 0) break;
vc.erase(vc.begin());
ans++;
}
printf("%d", ans);
//system("PAUSE");
return 0;
}