一开始看到题目感觉很难
然后看到题解感觉这题贼简单,我好像想复杂了
就算出每一行最少的资源(完全背包+二分)然后就枚举就好了。
#include<cstdio>
#include<algorithm>
#include<cstring>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;const int MAXN = 212345;
const int MAXM = 112;
int n, m, k;
int w[MAXM], p[MAXM], q[MAXN];
int f[MAXN], list[MAXN];int main()
{scanf("%d%d%d", &m, &n, &k);REP(i, 0, m) scanf("%d", &w[i]);REP(i, 0, m) scanf("%d", &p[i]);REP(i, 0, n) scanf("%d", &q[i]);REP(i, 0, m) REP(j, w[i], k + 1)f[j] = max(f[j], f[j-w[i]]+p[i]);int head = 0, sum = 0, ans = 0;REP(i, 0, n){int t = lower_bound(f, f + k + 1, q[i]) - f;//不是二分答案都用stl二分,简单又不会错 sum += t; list[i] = t;while(sum > k) sum -= list[head++]; //注意这里是whileans = max(ans, i - head + 1);}printf("%d\n", ans);return 0;
}