447D - DZY Loves Modification

思路:将行和列分开考虑。用优先队列,计算出行操作i次的幸福值r[i],再计算出列操作i次的幸福值c[i]。然后将行取i次操作和列取k-i次操作,那么多加的幸福值就是i*(k-i)*p,因为无论先操作行还是列,每操作一次一个格子只减一次p。这样记录下最大的幸福值。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e6+;
const int M=1e3+;
const ll INF=1e18;
priority_queue<ll>row,col;
ll r[N],c[N];
int a[M][M];
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n,m,k,p;
cin>>n>>m>>k>>p;
for(int i=;i<n;i++)
{
ll sum=;
for(int j=;j<m;j++)
{
cin>>a[i][j];
sum+=a[i][j];
}
row.push(sum);
}
for(int j=;j<m;j++)
{
ll sum=;
for(int i=;i<n;i++)
sum+=a[i][j];
col.push(sum);
}
for(int i=;i<=k;i++)
{
ll temp=row.top();
row.pop();
r[i]=r[i-]+temp;
row.push(temp-m*p);
}
for(int i=;i<=k;i++)
{
ll temp=col.top();
col.pop();
c[i]=c[i-]+temp;
col.push(temp-n*p);
}
ll ans=-INF;
for(int i=;i<=k;i++)
{
ans=max(ans,r[i]+c[k-i]-1ll*i*(k-i)*p);
}
cout<<ans<<endl;
return ;
}

Codeforces 447D - DZY Loves Modification的更多相关文章

  1. CodeForces 446B DZY Loves Modification

    题意: k次操作  每次选择一行或一列  得到所选数字的和  并将所选数字同一时候减去p  问最多得到多少 思路: 重点在消除行列间的相互影响 因为每选一行全部列所相应的和都会-p  那么假设选了i次 ...

  2. [CodeForces - 447D] D - DZY Loves Modification

    D - DZY Loves Modification As we know, DZY loves playing games. One day DZY decided to play with a n ...

  3. Codeforces Round #FF (Div. 1) B. DZY Loves Modification 优先队列

    B. DZY Loves Modification 题目连接: http://www.codeforces.com/contest/446/problem/B Description As we kn ...

  4. Codeforces Round #FF (Div. 2) D. DZY Loves Modification 优先队列

    D. DZY Loves Modification time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  5. Codeforces Round #FF (Div. 1) B. DZY Loves Modification

    枚举行取了多少次,如行取了i次,列就取了k-i次,假设行列单独贪心考虑然后相加,那么有i*(k-i)个交点是多出来的:dpr[i]+dpc[k-i]-i*(k-i)*p 枚举i取最大值.... B. ...

  6. Codeforces 444C DZY Loves Colors(线段树)

    题目大意:Codeforces 444C DZY Loves Colors 题目大意:两种操作,1是改动区间上l到r上面德值为x,2是询问l到r区间总的改动值. 解题思路:线段树模板题. #inclu ...

  7. D. DZY Loves Modification

    D. DZY Loves Modification time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  8. B. DZY Loves Modification

    B. DZY Loves Modification time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  9. Codeforces 444A DZY Loves Physics(图论)

    题目链接:Codeforces 444A DZY Loves Physics 题目大意:给出一张图,图中的每一个节点,每条边都有一个权值.如今有从中挑出一张子图,要求子图联通,而且被选中的随意两点.假 ...

随机推荐

  1. 001-Two Sum

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  2. 008-centos服务管理

  3. python excel操作 练习-#操作单列 #操作A到C列 #操作1到3行 #指定一个范围遍历所有行和列 #获取所有行 #获取所有列

    ##操作单列#操作A到C列#操作1到3行#指定一个范围遍历所有行和列#获取所有行#获取所有列 #coding=utf-8 from openpyxl import Workbook wb=Workbo ...

  4. Linux基础命令---swapon

    swapon 在指定的设备上启用交换分区,使用的设备或文件由专用文件参数提供.它可以是”-L label”或”-U UUID”,以指示一个设备的标签或UUID.对swapon的调用通常发生在系统引导脚 ...

  5. Js基础知识6-JavaScript匿名函数和闭包

    匿名函数 1,把匿名函数赋值给变量 var test = function() { return 'guoyu'; }; alert(test);//test是个函数 alert(test()); 2 ...

  6. P3008 [USACO11JAN]道路和飞机Roads and Planes

    P3008 [USACO11JAN]道路和飞机Roads and Planes Dijkstra+Tarjan 因为题目有特殊限制所以不用担心负权的问题 但是朴素的Dijkstra就算用堆优化,也显然 ...

  7. 20145339顿珠 Exp5 MSF基础应用

    20145339顿珠 Exp5 MS08_067漏洞测试 实验过程 IP地址:192.168.1.104 虚拟机ip:192.168.1.102 在控制台内使用search ms08_067查看相关信 ...

  8. Python3基础 tuple 通过拆分元素 把元组的数据删除

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. Python3基础 while 循环示例

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  10. Python3基础 break while循环示例

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...