标签:acm codeforces dp
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; }
Codeforces Round #214 (Div. 2)——Dima and Salad,布布扣,bubuko.com
Codeforces Round #214 (Div. 2)——Dima and Salad
标签:acm codeforces dp
原文地址:http://blog.csdn.net/wty__/article/details/25832805