Codeforces # FF (div2) d dzy Loves Modification,

Source: Internet
Author: User

Codeforces # FF (div2) d dzy Loves Modification,

First, we need to know that the order of selecting rows and columns is irrelevant.

Two arrays, row [I] and col [j], are used to indicate the maximum value that can be obtained by selecting only row I and the maximum value that can be obtained by selecting only column j.

This is maintained using a priority queue. After a row (column) is not selected, the sum of the row (column) minus the corresponding np (mp) is added to the queue.


If the number of rows selected for enumeration is I, the number of columns selected is k-I, and ans = row [I] + col [k-I]-(k-I) * I * p;

Since the sequence is irrelevant, we can see that the I-I row is selected first, I * p is subtracted each time a column is selected, and k-I column is selected, that is, minus (k-I) * I * p


//#pragma comment(linker, "/STACK:102400000,102400000")//HEAD#include <cstdio>#include <cstring>#include <vector>#include <iostream>#include <algorithm>#include <queue>#include <string>#include <set>#include <stack>#include <map>#include <cmath>#include <cstdlib>using namespace std;//LOOP#define FE(i, a, b) for(int i = (a); i <= (b); ++i)#define FED(i, b, a) for(int i = (b); i>= (a); --i)#define REP(i, N) for(int i = 0; i < (N); ++i)#define CLR(A,value) memset(A,value,sizeof(A))//STL#define PB push_back//INPUT#define RI(n) scanf("%d", &n)#define RII(n, m) scanf("%d%d", &n, &m)#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)#define RS(s) scanf("%s", s)#define FF(i, a, b) for(int i = (a); i < (b); ++i)#define FD(i, b, a) for(int i = (b) - 1; i >= (a); --i)#define CPY(a, b) memcpy(a, b, sizeof(a))#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)#define EQ(a, b) (fabs((a) - (b)) <= 1e-10)#define ALL(c) (c).begin(), (c).end()#define SZ(V) (int)V.size()#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)#define WI(n) printf("%d\n", n)#define WS(s) printf("%s\n", s)#define sqr(x) x * xtypedef vector <int> VI;typedef unsigned long long ULL;typedef long long LL;const int INF = 0x3f3f3f3f;const int maxn = 1010;const double eps = 1e-10;const LL MOD = 1e9 + 7;int ipt[maxn][maxn];LL row[maxn * maxn], col[maxn * maxn];LL rtol[maxn], ctol[maxn];int main(){    int n, m, k, p;    while (~RIV(n, m, k, p))    {        priority_queue<LL> r, c;        int radd = 0, cadd = 0;        CLR(rtol, 0), CLR(ctol, 0);        FE(i, 1, n)            FE(j, 1, m)            {                RI(ipt[i][j]);                rtol[i] += ipt[i][j];                ctol[j] += ipt[i][j];            }        FE(i, 1, n)            r.push(rtol[i]);        FE(j, 1, m)            c.push(ctol[j]);        row[0] = 0, col[0] = 0;        FE(i, 1, k)        {            LL x = r.top(), y = c.top();             r.pop(), c.pop();            r.push(x - m * p);            c.push(y - n * p);            row[i] = row[i - 1] + x;            col[i] = col[i - 1] + y;        }//        FE(i, 0, k)//            cout << row[i] + col[k - i] <<endl;        LL ans = -1e18;        FE(i, 0, k)            ans = max(ans, row[i] + col[k - i] - (LL)i * (k - i)* p);        cout << ans << endl;    }    return 0;}/*2 2 4 21 2 3 102 3 5 22 2 22 2 2*/



Codeforces question: How can I attack others in codeforces?

For a question, you must first pass TEST. Then return to the PROBLEM list of the game, lock the lock behind the question (the lock won't be submitted again, so don't lock it if you're unsure), and then go to the ROOM, you can check other people's Code. There is a HACK button below. Click it and enter the example that you think is wrong.

How can codeforces view the test data after the competition ends?

Click standing and double-click the person passing through the standing. The AC is the AC code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.