Cod sursa(job #3360699)

Utilizator repmannFilip Repman repmann Data 16 iulie 2026 00:46:50
Problema Elimin Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <bits/stdc++.h>
using namespace std;
int N, M, R, C;
int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> N >> M >> R >> C;
  int A[min(N, M)][max(N, M)];
  for(int i = 0; i < N; i++)
  {
    for(int j = 0; j < M; j++)
    {
      if(N < M) cin >> A[i][j];
      else cin >> A[j][i];
    }
  }
  if(N > M) {swap(N, M); swap(R, C);}
  int mx = 0, temp, SUM[M];
  for(int mask = 0; mask < (1 << N); mask++)
  {
    if(__builtin_popcount(mask) != R) continue;
    for(int j = 0; j < M; j++) SUM[j] = 0;
    for(int i = 0; i < N; i++)
    {
      if(mask & (1 << i)) continue;
      for(int j = 0; j < M; j++) SUM[j] += A[i][j];
    }
    sort(SUM, SUM + M);
    temp = 0;
    for(int j = C; j < M; j++) temp += SUM[j];
    mx = max(temp, mx);
  }
  cout << mx << '\n';

  return 0;
}