結果
問題 | No.617 Nafmo、買い出しに行く |
ユーザー |
![]() |
提出日時 | 2018-04-05 00:30:25 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 498 bytes |
コンパイル時間 | 722 ms |
コンパイル使用メモリ | 58,524 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 08:59:07 |
合計ジャッジ時間 | 1,761 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘void solve()’: main.cpp:27:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d %d", &n, &k); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:29:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | scanf("%d", A + i); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <algorithm> #include <deque> #include <string> #include <iostream> using namespace std; using ll = long long; void solve(); int main() { solve(); #ifdef DBG while (true); #endif } //617 int n, k, A[20]; int rec(int i, int w) { if (n <= i) return w; int r = (w + A[i] <= k) ? rec(i + 1, w + A[i]) : w; r = max(r, rec(i + 1, w)); return r; } void solve() { scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", A + i); printf("%d\n", rec(0, 0)); }