結果
問題 | No.1163 I want to be a high achiever |
ユーザー |
![]() |
提出日時 | 2020-08-13 20:38:54 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 1,382 bytes |
コンパイル時間 | 987 ms |
コンパイル使用メモリ | 95,432 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-09 19:32:24 |
合計ジャッジ時間 | 1,948 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 3 ms
6,816 KB |
testcase_05 | AC | 3 ms
6,816 KB |
testcase_06 | AC | 4 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 4 ms
6,820 KB |
testcase_10 | AC | 3 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,816 KB |
testcase_12 | AC | 3 ms
6,816 KB |
testcase_13 | AC | 4 ms
6,824 KB |
testcase_14 | AC | 4 ms
6,816 KB |
testcase_15 | AC | 2 ms
6,820 KB |
testcase_16 | AC | 3 ms
6,816 KB |
testcase_17 | AC | 2 ms
6,820 KB |
testcase_18 | AC | 2 ms
6,820 KB |
testcase_19 | AC | 4 ms
6,816 KB |
testcase_20 | AC | 4 ms
6,816 KB |
testcase_21 | AC | 5 ms
6,816 KB |
testcase_22 | AC | 3 ms
6,816 KB |
testcase_23 | AC | 3 ms
6,816 KB |
testcase_24 | AC | 2 ms
6,816 KB |
testcase_25 | AC | 3 ms
6,816 KB |
testcase_26 | AC | 2 ms
6,820 KB |
testcase_27 | AC | 2 ms
6,816 KB |
testcase_28 | AC | 2 ms
6,820 KB |
testcase_29 | AC | 2 ms
6,816 KB |
testcase_30 | AC | 2 ms
6,816 KB |
testcase_31 | AC | 2 ms
6,820 KB |
testcase_32 | AC | 2 ms
6,820 KB |
ソースコード
/* -*- coding: utf-8 -*- * * 1163.cc: No.1163 I want to be a high achiever - yukicoder */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 500; const int MAX_A = 100; const int MAX_K = MAX_N * MAX_A; /* typedef */ /* global variables */ int as[MAX_N], bs[MAX_N]; int dp[MAX_K + 1]; /* subroutines */ inline void setmax(int &a, int b) { if (a < b) a = b; } /* main */ int main() { int n, x; scanf("%d%d", &n, &x); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0; i < n; i++) scanf("%d", bs + i); int m = 0, k = 0, bsum = 0; for (int i = 0; i < n; i++) { int d = as[i] - x; if (d >= 0) k += d; else { as[m] = -d, bs[m] = bs[i]; bsum += bs[i]; m++; } } if (m == n) { puts("-1"); return 0; } memset(dp, -1, sizeof(dp)); dp[k] = 0; for (int i = 0; i < m; i++) for (int j = as[i]; j <= k; j++) if (dp[j] >= 0) setmax(dp[j - as[i]], dp[j] + bs[i]); int maxd = 0; for (int j = 0; j <= k; j++) setmax(maxd, dp[j]); printf("%d\n", bsum - maxd); return 0; }