This is indeed a good question ~ At that time, I only thought we should do it with greed...
Later, I was told that the relationship between greedy local and global optimal solutions should not be strictly established ~
Touch me
There is always a solution to this problem.
1 #include <iostream> 2 #include <cstdio> 3 #include <queue> 4 using namespace std; 5 6 typedef long long LL; 7 const int size = 1000010; 8 const LL inf = 1e18; 9 LL a[1010] , b[1010];10 LL row[size] , col[size];11 priority_queue<LL>rowQu,colQu;12 13 int main()14 {15 cin.sync_with_stdio(false);16 LL n , m , k , p , i , j , num , ans , temp;17 while( cin >> n >> m >> k >> p )18 {19 for( i = 1 ; i<=n ; i++ )20 {21 for( j = 1 ; j<=m ; j++ )22 {23 cin >> num;24 a[i] += num;25 b[j] += num;26 }27 rowQu.push(a[i]); 28 }29 for( j = 1 ; j<=m ; j++ )30 {31 colQu.push(b[j]);32 }33 ans = -inf;34 for( i = 1 ; i<=k ; i++ )35 {36 temp = rowQu.top();37 rowQu.pop();38 row[i] = row[i-1] + temp;39 rowQu.push(temp-m*p);40 41 temp = colQu.top();42 colQu.pop();43 col[i] = col[i-1] + temp;44 colQu.push(temp-n*p);45 }46 for( i = 0 ; i<=k ; i++ )47 {48 temp = row[i] + col[k-i];49 temp -= (i)*(k-i)*p;50 if( temp>ans )51 ans = temp;52 }53 cout << ans << endl;54 }55 return 0; 56 }View code
Here, because the data is very big and 64-bit, ANS should be set small enough... at the beginning, I will use my usual 0x3f3f3f3f To wa ~
In the future, I will do a good job in every CF scenario. In the future, I will post the CF post, but I will only learn it when I come to see other people's problem-solving reports ~
// I woke up until half past two P.M. today. The World Cup is over.
Today:
This is a world that is popular, but we are not good at saying goodbye ~
You have finally lived like a general human behavior specification, removing your expression and hiding your emotions without a trace of popularity ~