This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=1505, of=1505;
ll dp[MX][2*MX];
ll par[MX][2*MX];
int cur[MX];
long long find_maximum(int k, std::vector<std::vector<int>> d) {
int N=d.size();
int M=d[0].size();
if(k==M) {
priority_queue<pair<int,int>> pq;
for(int i=0;i<N;i++) {
pq.push({-d[i][0],i});
cur[i]=0;
}
ll ans=0;
int bal=N/2*M;
while(!pq.empty() && bal>0) {
auto [q,i]=pq.top(); pq.pop();
bal--;
q=-q;
ans-=q;
cur[i]++;
if(cur[i]<M) {
pq.push({-d[i][cur[i]],i});
}
}
vector<vector<int>> s(N,vector<int>(M,-1));
vector<pair<int,int>> v;
for(int i=0;i<N;i++) {
v.push_back({cur[i]-1,i});
for(int j=cur[i];j<M;j++) {
ans+=d[i][j];
}
}
vector<int> fr(N), bk(N,M-1);
for(int x=0;x<k;x++) {
sort(v.rbegin(),v.rend());
for(int j=0;j<N/2;j++) {
auto &[y,i]=v[j];
s[i][fr[i]]=x;
fr[i]++;
y--;
}
for(int j=N/2;j<N;j++) {
auto &[y,i]=v[j];
s[i][bk[i]]=x;
bk[i]--;
}
}
allocate_tickets(s);
return ans;
}
vector<pair<int,int>> v;
for(int i=0;i<N;i++) v.push_back({d[i].front(),d[i].back()});
for(int i=0;i<MX;i++)
for(int j=0;j<2*MX;j++)
dp[i][j]=-1e18;
dp[0][0+of]=0;
for(int i=0;i<N;i++) {
for(int j=-N;j<=N;j++) {
if(dp[i][j+of]==-1e18) continue;
if(dp[i][j+of]+v[i].second>dp[i+1][j+1+of]) {
dp[i+1][j+1+of]=dp[i][j+of]+v[i].second;
par[i+1][j+1+of]=1;
}
if(dp[i][j+of]-v[i].first>dp[i+1][j-1+of]) {
dp[i+1][j-1+of]=dp[i][j+of]-v[i].first;
par[i+1][j-1+of]=-1;
}
}
}
vector<vector<int>> s(N,vector<int>(M,-1));
int cur=N, bal=0;
while(cur>0) {
if(par[cur][bal+of]>0) s[cur-1].back()=0;
else s[cur-1].front()=0;
bal-=par[cur][bal+of];
cur--;
}
allocate_tickets(s);
return dp[N][0+of];
}
# | 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... |