时间:2021-07-01 10:21:17 帮助过:27人阅读
const int MAXN = 110;const int M = 210000;int tastes[MAXN], calories[MAXN];int v[MAXN];int dp[2][M];int main(){// freopen("in.txt", "r", stdin); int n, m; while (~RII(n, m)) { REP(i, n) RI(tastes[i]); REP(i, n) RI(calories[i]); REP(i, n) v[i] = tastes[i] - calories[i] * m; CLR(dp, -INF); dp[0][0] = dp[1][0] = 0; REP(i, n) { int cnt = v[i] < 0, val = abs(v[i]); FED(j, M - val - 1, 0) dp[cnt][j + val] = max(dp[cnt][j + val], dp[cnt][j] + tastes[i]); } int ans = 0; REP(i, M) ans = max(ans, dp[0][i] + dp[1][i]); if (ans <= 0) puts("-1"); else WI(ans); } return 0;}