Idea: goncharovmike, prepared: pashka
t = int(input())
for _ in range(t):
a = [[int(x) for x in input().split()] for i in range(4)]
x = [p[0] for p in a]
dx = max(x) - min(x)
print(dx * dx)
Idea: pashka, prepared: ikrpprppp
t = int(input())
for _ in range(t):
n = int(input())
start = [int(x) for x in input()]
finish = [int(x) for x in input()]
pairs = list(zip(start, finish))
add_amnt = sum(int(a < b) for a, b in pairs)
rmv_amnt = sum(int(a > b) for a, b in pairs)
print(max(add_amnt, rmv_amnt))
Idea: step_by_step, prepared: step_by_step
t = int(input())
for _ in range(t):
n, f, a, b = map(int, input().split())
m = [0] + [int(x) for x in input().split()]
for i in range(1, n + 1):
f -= min(a * (m[i] - m[i - 1]), b)
print('YES' if f > 0 else 'NO')
1921D - Сильно отличающийся массив
Idea: Vitaly503, prepared: pashka
~~~~~
include <bits/stdc++.h>
using namespace std;
struct test { void solve() { int n, m; cin >> n >> m; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector b(m); for (int i = 0; i < m; i++) cin >> b[i]; sort(a.begin(), a.end()); sort(b.rbegin(), b.rend()); vector c(n); long long s = 0; for (int i = 0; i < n; i++) { c[i] = b[m — n + i]; s += abs(c[i] — a[i]); } long long res = 0; for (int k = 0; k <= n; k++) { res = max(res, s); if (k < n) { s -= abs(c[k] — a[k]); c[k] = b[k]; s += abs(c[k] — a[k]); } } cout << res << "\n"; } };
int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) { test().solve(); } return 0; }~~~~~
Idea: ikrpprppp, prepared: ikrpprppp
def solve():
h, w, xA, yA, xB, yB = map(int, input().split())
if (xA - xB) % 2 == 0:
winner = "Bob"
if xA >= xB:
win = False
elif yA == yB:
win = True
else:
if yA < yB:
n_turns = yB - 1
else:
n_turns = w - yB
win = xB - 2 * n_turns >= xA
else:
winner = "Alice"
xA += 1
yA += 0 if yB - yA == 0 else 1 if yB - yA > 0 else -1
if xA > xB:
win = False
elif yA == yB:
win = True
else:
if yA < yB:
n_turns = w - yA
else:
n_turns = yA - 1
win = xB - 2 * n_turns >= xA
print(winner if win else "Draw")
t = int(input())
for _ in range(t):
solve()
Idea: Vitaly503, prepared: Vitaly503
#include <bits/stdc++.h>
using namespace std;
long long precalc[322][200322];
long long precalci[322][200322];
void solve() {
int n, q;
cin >> n >> q;
vector<long long> a(n);
int pivot = 1;
while (pivot * pivot < n) {
pivot++;
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < pivot; i++) {
for (int j = 0; j <= i; j++) {
precalc[i][j] = 0LL;
precalci[i][j] = 0LL;
}
for (int j = 0; j < n; j++) {
precalci[i][j + i + 1] = precalci[i][j] + a[j] * (j / (i + 1) + 1);
precalc[i][j + i + 1] = precalc[i][j] + a[j];
}
}
while (q--) {
int s, d;
long long k;
long long ans = 0;
cin >> s >> d >> k;
s--;
if (d > pivot) {
for (int i = s; i <= s + (k - 1) * d; i += d) {
ans += a[i] * ((i - s) / d + 1);
}
cout << ans << " ";
continue;
}
long long last = s + d * k - d;
int first = s;
cout << precalci[d - 1][last + d] - precalci[d - 1][first] -
(precalc[d - 1][last + d] - precalc[d - 1][first]) * (first / d) << ' ';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tests;
cin >> tests;
while (tests--) {
solve();
if (tests) cout << "\n";
}
return 0;
}
Idea: Vitaly503, prepared: goncharovmike
//ciao_chill
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n, m, k;
vector<vector<int>> a;
bool prov(int i, int j) {
return 0 <= i && i < n && 0 <= j && j < m;
}
int ans() {
int cnt = 0;
int dp[n][m];
int pref[n][m];
int pref_up[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
pref_up[i][j] = a[i][j];
if (prov(i - 1, j))
pref_up[i][j] += pref_up[i - 1][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = m - 1; j >= 0; j--) {
pref[i][j] = a[i][j];
if (prov(i - 1, j + 1))
pref[i][j] += pref[i - 1][j + 1];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
dp[i][j] = pref_up[i][j];
if (prov(i - k, j))
dp[i][j] -= pref_up[i - k][j];
if (prov(i, j - 1))
dp[i][j] += dp[i][j - 1];
if (j < k) {
int i1 = j - k + i;
if (i1 >= 0)
dp[i][j] -= pref[i1][0];
}
else
dp[i][j] -= pref[i][j - k];
if (prov(i - k, j))
dp[i][j] += pref[i - k][j];
cnt = max(cnt, dp[i][j]);
}
}
return cnt;
}
void solve() {
cin >> n >> m >> k;
k++;
char c;
bool st[n][m];
a.resize(n);
for (int i = 0; i < n; i++) {
a[i].resize(m);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
{
cin >> c;
st[i][j] = (c == '#');
a[i][j] = st[i][j];
}
}
int mx = ans();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = st[n - i - 1][j];
}
}
mx = max(mx, ans());
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = st[i][m - j - 1];
}
}
mx = max(mx, ans());
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = st[n - i - 1][m - j - 1];
}
}
mx = max(mx, ans());
cout << mx << '\n';
}
signed main() {
cin.tie(nullptr);
cout.tie(nullptr);
ios_base::sync_with_stdio(false);
int tt;
cin >> tt;
while (tt--)
solve();
return 0;
}