#include<bits/stdc++.h> #define int long long #define endl '\n' typedeflonglong ll; usingnamespace std; ll a[(int)1e5 * 2 + 10], s[(int)1e5 * 2 + 10]; voidsolve(){ int n, k; ll ans = 1e18; cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a, a + n + 1); for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + a[i]; for (int p = 0; p <= k; ++p) ans = min(s[2 * p] + s[n] - s[n + p - k], ans); cout << ans << endl; } signedmain(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) solve(); return0; }
#include<bits/stdc++.h> #define mod (int)(1e9 + 7) #define int long long #define endl '\n' typedeflonglong ll; usingnamespace std; ll a[1010][1010], s[1010][1010]; voidsolve(){ int n, m, c; cin >> n >> m >> c; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) { cin >> a[i][j]; s[i][j] = s[i - 1][j] + s[i][j - 1] + a[i][j] - s[i - 1][j - 1]; } int ans = -1e18, sum; int x = -1, y = -1; for (int i = 1; i <= n - c + 1; ++i) { for (int j = 1; j <= m - c + 1; ++j) { int rx = i + c - 1, ry = j + c - 1; // 加上 s[rx - c][ry - c] 是因为两块区域重复了 sum = s[rx][ry] - s[rx - c][ry] + s[rx - c][ry - c] - s[rx][ry - c]; if (sum > ans) { ans = sum; x = i; y = j; } } } cout << x << " " << y << endl; } signedmain(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) solve(); return0; }