結果
問題 |
No.5 数字のブロック
|
ユーザー |
![]() |
提出日時 | 2015-03-20 19:06:54 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 804 bytes |
コンパイル時間 | 614 ms |
コンパイル使用メモリ | 84,124 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-28 23:47:12 |
合計ジャッジ時間 | 1,509 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 WA * 10 |
コンパイルメッセージ
main.cpp: In function ‘int solve(int, int)’: main.cpp:28:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 28 | for (int i = 0; i < n; i++) scanf("%d", &w[i]); | ~~~~~^~~~~~~~~~~~~ main.cpp: In function ‘int main()’: main.cpp:41:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 41 | scanf("%d%d", &l, &n); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <algorithm> #include <iostream> #include <cstdio> #include <map> #include <numeric> #include <cmath> #include <set> #include <sstream> #include <string> #include <vector> #include <queue> #include <complex> #include <string.h> using namespace std; #define endl '\n' #define all(v) (v).begin(), (v).end() #define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end()) typedef long long ll; typedef pair<int, int> P; typedef unsigned int uint; const int inf = 1000000009; int solve(int l, int n) { vector<int> w(n); for (int i = 0; i < n; i++) scanf("%d", &w[i]); sort(all(w)); int sum = 0; int idx = 0; while (sum <= l) { sum += w[idx]; idx++; } return idx-1; } int main() { int l, n; scanf("%d%d", &l, &n); printf("%d\n", solve(l, n)); }