signedmain(){ int n; std::cin >> n; int a = INT_MIN, b = INT_MAX, c = INT_MIN, d = INT_MAX; for (int i = 0; i < n; i++) { int x, y; std::cin >> x >> y; a = std::max(x, a); b = std::min(b, x); c = std::max(c, y); d = std::min(d, y); } // std::cout << a << ' ' << b << '\n'; int ans = std::max((c - d + 1) / 2, (a - b + 1) / 2); std::cout << ans << '\n'; return0; }
#include<bits/stdc++.h>n int p[510][510]; int memo[510][510];
signedmain(){ int n, m, l; std::cin >> n >> m >> l; std::vector<int> a(n); std::vector<std::vector<int>> b(l); for (int i = 0; i < n; i++) { std::cin >> a[i]; b[i % l].push_back(a[i]); } for (int i = 0; i < m; i++) { for (int j = 0; j < l; j++) { int sum = 0; for (auto x : b[j]) { if (x <= i) { sum += i - x; } else { sum += m + i - x; } } p[j][i] = sum; } } memset(memo, -1, sizeof(memo)); auto dfs = [&](auto&& dfs, int u, int s) -> int { if (u == l) { if (s == 0) { return0; } else { return (n / l) * (m - s); } } int& res = memo[u][s]; if (res != -1) { return res; } res = INT_MAX; for (int i = 0; i < m; i++) { res = std::min(res, dfs(dfs, u + 1, (s + i) % m) + p[u][i]); } return res; }; int ans = dfs(dfs, 0, 0); std::cout << ans << '\n'; return0; }