Pagini recente » Cod sursa (job #3252997) | Cod sursa (job #1291018) | Cod sursa (job #3216699) | Cod sursa (job #1032282) | Cod sursa (job #3221637)
#include <bits/stdc++.h>
#define fi first
#define se second
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define lsb(x) (x & (-x))
#define YES { fout << "DA" << endl; return; }
#define NO { fout << "NU" << endl; return; }
using ll = long long;
using pii = std::pair<int, int>;
const int NMAX = 73e2;
using namespace std;
ifstream fin ("elimin.in");
ofstream fout ("elimin.out");
int n, m, r, c;
pii splin[NMAX + 5], spcol[NMAX + 5];
set<pii>s;
signed main() {
fin >> n >> m >> r >> c;
int mat[n + 5][m + 5];
memset(mat, 0, sizeof(mat));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
fin >> mat[i][j], splin[i].fi += mat[i][j], spcol[j].fi += mat[i][j];
for (int i = 1; i <= n; i++)
splin[i].se = i;
for (int j = 1; j <= m; j++)
spcol[j].se = j;
sort(splin + 1, splin + n + 1);
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= m; j++)
s.insert({splin[i].se, j}), spcol[j].fi -= mat[splin[i].se][j];
}
sort(spcol + 1, spcol + m + 1);
for (int j = 1; j <= c; j++){
for (int i = 1; i <= n; i++)
s.insert({i, spcol[j].se});
}
int ans = 0;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++)
ans += (s.find({i, j}) == s.end()) * mat[i][j];
}
fout << ans << "\n";
return 0;
}