#include <iostream>
#include <algorithm>
#include <vector>
#include "tickets.h"
using namespace std;
#define ll long long
vector<vector<ll>> x;
vector<vector<pair<ll, ll>>> dp;
ll n, m;
pair<ll, ll> makeDp(ll indx, ll used_high){
if(used_high >= indx+1) return{-1, -1};
if(dp[indx][used_high].first != -1) return dp[indx][used_high];
if(indx == 0){
if(used_high == 1) return dp[indx][used_high] = {x[indx][m-1], m-1};
if(used_high == 0) return dp[indx][used_high] = {-x[indx][0], 0};
}
dp[indx][used_high] = {makeDp(indx-1, used_high).first - (ll)x[indx][0], 0};
if(used_high && dp[indx][used_high].first < makeDp(indx-1, used_high-1).first + (ll)x[indx][m-1]){
dp[indx][used_high] = {makeDp(indx-1, used_high-1).first + (ll)x[indx][m-1], m-1};
}
return dp[indx][used_high];
}
ll find_maximum(int k, vector<vector<int>> x1){
n = x1.size();
m = x1[0].size();
x.assign(n, vector<ll>(m, 0));
for(int i = 0; i<n; i++) for(int j = 0; j<m; j++) x[i][j] = (ll)x1[i][j];
if(m == 1){
sort(x.begin(), x.end());
ll ans = 0;
for(ll i = 0; i<n/2; i++) ans -= (ll)x[i][0];
for(ll i = n/2; i<n; i++) ans += (ll)x[i][0];
vector<vector<int>> arr(n, vector<int>(1, 0));
allocate_tickets(arr);
return ans;
}
else{
dp.assign(n, vector<pair<ll, ll>>(n, pair<ll, ll>(-1, -1)));
ll ans = makeDp(n-1, n/2).first;
vector<vector<int>> arr(n, vector<int>(m, -1));
ll uh = n/2;
for(ll i = n-1; i>=0; i--){
arr[i][dp[i][uh].second] = 0;
if(dp[i][uh].second == m-1) uh--;
}
allocate_tickets(arr);
return ans;
}
}
// ll main(void){
// freopen("input.txt", "r", stdin);
// ll n1, m1, k1;
// cin>>n1>>m1>>k1;
// vector<vector<ll>> t;
// t.assign(n1, vector<ll>(m1, 0));
// for(ll i = 0; i<n1; i++) for(ll j = 0; j<m1; j++) cin>>t[i][j];
// cout<<find_maximum(k1, t);
// }
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |