cf1060E. Sergey and Subway(思维 枚举)
程序员文章站
2023-11-17 22:35:58
题意 "题目链接" Sol 好好读题 = 送分题 不好好读题 = 送命题 开始想了$30$min数据结构发现根本不会做,重新读了一遍题发现是个傻逼题。。。 $C_{i, j} = a[i] b[j]$ 根据乘法分配律,题目就变成了在数组$a, b$中分别选一段连续的区间,要求权值和相乘$ defin ......
题意
sol
好好读题 => 送分题
不好好读题 => 送命题
开始想了\(30\)min数据结构发现根本不会做,重新读了一遍题发现是个傻逼题。。。
\(c_{i, j} = a[i] * b[j]\)
根据乘法分配律,题目就变成了在数组\(a, b\)中分别选一段连续的区间,要求权值和相乘\(<= x\),最大化区间长度乘积
\(n^2\)模拟一下即可
#include<bits/stdc++.h> #define pair pair<int, int> #define mp(x, y) make_pair(x, y) #define fi first #define se second #define int long long #define ll long long #define rg register #define pt(x) printf("%d ", x); #define fin(x) {freopen(#x".in","r",stdin);} #define fout(x) {freopen(#x".out","w",stdout);} #define chmin(x, y) (x = x < y ? x : y) using namespace std; const int maxn = 2001, inf = 1e18 + 10, mod = 1e9 + 7; const double eps = 1e-9; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int n, m, a[maxn], b[maxn], f[maxn], g[maxn], lim, ans; main() { n = read(); m = read(); for(int i = 1; i <= n; i++) a[i] = read(); for(int i = 1; i <= m; i++) b[i] = read(); memset(f, 0x7f, sizeof(f)); memset(g, 0x7f, sizeof(g)); lim = read(); for(int i = 1; i <= n; i++) { int mn = 0; for(int j = i; j <= n; j++) mn += a[j], chmin(f[j - i + 1], mn); } for(int i = 1; i <= m; i++) { int mn = 0; for(int j = i; j <= m; j++) mn += b[j], chmin(g[j - i + 1], mn); } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(f[i] * g[j] <= lim) ans = max(ans, j * i); } } cout << ans; return 0; }