Pagini recente » Monitorul de evaluare | Cod sursa (job #3233006) | Atasamentele paginii Profil AndreiFlorescu | Monitorul de evaluare | Cod sursa (job #3353838)
#include <bits/stdc++.h>
using namespace std;
int n,m,rr,cc,a[7294],s[7294],sr[15],sol,sumall,o[7294];
const int dim=1<<20;
char buff[dim];
int poz,lg;
char getch() {
if(poz==lg){
lg=fread(buff,1,dim,stdin);
poz=0;
}
return poz==lg?0:buff[poz++];
}
int read() {
int x=0;
char ch=getch();
while(ch&&(ch<'0'||ch>'9')) {
ch=getch();
}
while(ch>='0'&&ch<='9') {
x=x*10+ch-'0';
ch=getch();
}
return x;
}
bool cmp(int i,int j) {
return s[i]>s[j];
}
void bkt(int pos,int go) {
if(n-go+pos<rr){
return;
}
if(pos==rr) {
nth_element(o,o+(m-cc),o+m,cmp);
int now=0;
if(m-cc<cc) {
for(int i=0;i<m-cc;i++){
now+=s[o[i]];
}
}else{
now=sumall;
for(int i=m-cc;i<m;i++) {
now-=s[o[i]];
}
}
sol=max(sol,now);
return;
}
for(int row=go;row<n;row++){
sumall-=sr[row];
for(int c=0;c<m;c++) {
s[c]-=a[row*m+c];
}
bkt(pos+1,row);
sumall+=sr[row];
for(int c=0;c<m;c++) {
s[c]+=a[row*m+c];
}
}
}
signed main() {
freopen("elimin.in","r",stdin);
freopen("elimin.out","w",stdout);
n=read();
m=read();
rr=read();
cc=read();
if(n<m){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++) {
a[i*m+j]=read();
}
}
}else{
for(int i=0;i<n;i++){
for(int j=0;j<m;j++) {
a[j*n+i]=read();
}
}
swap(n,m);
swap(rr,cc);
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
sr[i]+=a[i*m+j];
s[j]+=a[i*m+j];
sumall+=a[i*m+j];
}
}
for(int i=0;i<m;i++) {
o[i]=i;
}
bkt(0,0);
cout<<sol<<"\n";
return 0;
}