Educational Codeforces Round 108 (Rated for Div. 2)
Educational Codeforces Round 108 (Rated for Div. 2)
A - Red and Blue Beans
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n >> m >> k;
if (n > m) swap(n, m);
m -= n;
cout << (!m || (m - 1) / n + 1 <= k ? "YES\n" : "NO\n");
}
return 0;
}
B - The Cake Is a Lie
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n >> m >> k;
if (n < m) swap(n, m);
k -= n - 1 + (m - 1ll) * n;
cout << (!k ? "YES\n" : "NO\n");
}
return 0;
}
C - Berland Regional
排序之后对每个学校算对每种人数组队的贡献即可
int u[N];
ll s[N];
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n; map<int, vector<ll>> st;
rep (i, 1, n) cin >> u[i], s[i] = 0;
rep (i, 1, n) cin >> k, st[u[i]].pb(k);
for (auto &i : st) {
sort(all(i.se), greater<int>());
rep (j, 1, i.se.size() - 1) i.se[j] += i.se[j - 1];
rep (j, 1, i.se.size()) s[j] += i.se[i.se.size() / j * j - 1];
}
rep (i, 1, n) cout << s[i] << char(" \n"[i == n]);
}
return 0;
}
D - Maximum Sum of Products
区间dp模型
int a[N], b[N];
ll sum, mx, s[N][N];
int main() {
IOS; cin >> n;
rep (i, 1, n) cin >> a[i];
rep (i, 1, n) cin >> b[i], sum += (ll)a[i] * b[i];
rep (i, 2, n) rep (j, 1, n + 1 - i)
umax(mx, s[j][i + j - 1] = s[j + 1][i + j - 2] + (ll)(a[i + j - 1] - a[j]) * (b[j] - b[i + j - 1]));
cout << (sum + mx);
return 0;
}