Cod sursa(job #3313187)

Utilizator BuzdiBuzdugan Rares Andrei Buzdi Data 2 octombrie 2025 19:22:45
Problema Elimin Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.57 kb
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define ld long double

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ifstream fin("elimin.in");
ofstream fout("elimin.out");

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, m, r, c;
    fin >> n >> m >> r >> c;

    vector<vector<int>> a;
    if(n <= m) {
        a.resize(n, vector<int>(m));
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                fin >> a[i][j];
            }
        }
    }
    else {
        a.resize(m, vector<int>(n));
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                fin >> a[j][i];
            }
        }
        swap(n, m);
        swap(r, c);
    }

    int answer = 0;
    for(int mask = 0; mask < (1 << n); mask++) {
        if(__builtin_popcount(mask) != r) {
            continue;
        }

        vector<int> s(m);
        for(int i = 0; i < n; i++) {
            if(!(mask >> i & 1)) {
                for(int j = 0; j < m; j++) {
                    s[j] += a[i][j];
                }
            }
        }

        int answer_here = 0;
        sort(s.begin(), s.end());
        for(int i = c; i < m; i++) {
            answer_here += s[i];
        }
        answer = max(answer, answer_here);
    }
    fout << answer << '\n';
    return 0;
}