結果
問題 |
No.50 おもちゃ箱
|
ユーザー |
![]() |
提出日時 | 2016-09-05 05:15:24 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 779 bytes |
コンパイル時間 | 433 ms |
コンパイル使用メモリ | 43,488 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 21:23:15 |
合計ジャッジ時間 | 1,463 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:44:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 44 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:45:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | INC(i, n) { scanf("%d", &a[i]); } | ~~~~~^~~~~~~~~~~~~ main.cpp:46:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 46 | scanf("%d", &m); | ~~~~~^~~~~~~~~~ main.cpp:47:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 47 | INC(i, m) { scanf("%d", &b[i]); } | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <algorithm> #include <functional> #define FOR(i, l, r) for(int i = (l) ; i < (r); i++) #define INC(i, n) FOR(i, 0, n) #define INC1(i, n) FOR(i, 1, (n) + 1) int n, m, a[10], b[10]; #define S(x) if(n <= x) { return i; } else { INC(c##x, i) { b[c##x] -= a[x]; if(b[c##x] >= 0) { #define E(x) } b[c##x] += a[x]; } } int search() { INC1(i, m) { S(0) S(1) S(2) S(3) S(4) S(5) S(6) S(7) S(8) S(9) return i; E(9) E(8) E(7) E(6) E(5) E(4) E(3) E(2) E(1) E(0) } return -1; } int main() { scanf("%d", &n); INC(i, n) { scanf("%d", &a[i]); } scanf("%d", &m); INC(i, m) { scanf("%d", &b[i]); } std::sort(b, b + m, std::greater<int>() ); // 降順ソート printf("%d\n", search() ); return 0; }