1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>

using namespace std;
typedef long long ll;
ll n, m, k;
const size_t M = 300'010;

ll best[M] = {};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n >> m >> k;
    for (auto i=1; i<=n; i++) {
        ll s = 0;
        for (auto j=1; j<=m; j++) {
            ll a;
            cin >> a;
            s += a;
            
            for (auto l=k; l>=j; l--)
                best[l] = max(s + best[l-j], best[l]);
        }
    }
    cout << best[k];
    return 0;
}