题目链接:http://codeforces.com/problemset/problem/446/B

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+3;
int matrix[N][N];
ll row[N],col[N];
ll dpr[N*N],dpc[N*N];
priority_queue <ll> q;
int main()
{
ll n,m,k,p;
scanf("%I64d%I64d%I64d%I64d",&n,&m,&k,&p);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&matrix[i][j]);
row[i]+=matrix[i][j];
col[j]+=matrix[i][j];
}
}
for(int i=1;i<=n;i++)
q.push(row[i]);
for(int i=1;i<=k;i++)
{
ll temp=q.top();
q.pop();
dpr[i]=dpr[i-1]+temp;
temp-=m*p;
q.push(temp);
}
while(!q.empty()) q.pop();
for(int i=1;i<=m;i++)
q.push(col[i]);
for(int i=1;i<=k;i++)
{
ll temp=q.top();
q.pop();
dpc[i]=dpc[i-1]+temp;
temp-=n*p;
q.push(temp);
}
ll ans=dpr[0]+dpc[k];
for(ll i=1;i<=k;i++)
ans=max(ans,dpr[i]+dpc[k-i]-i*(k-i)*p);
printf("%I64d\n",ans);
return 0;
}

codeforces 446B(优先队列)的更多相关文章

  1. CodeForces 446B DZY Loves Modification

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

  2. CodeForces 446B

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

  3. 【组队赛三】-D 优先队列 cf446B

    DZY Loves Modification Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Sub ...

  4. 11.1 正睿停课训练 Day14

    目录 2018.11.1 正睿停课训练 Day14 A 字符串 B 取数游戏(贪心) C 魔方(模拟) 考试代码 B C 2018.11.1 正睿停课训练 Day14 时间:3.5h 期望得分:100 ...

  5. codeforces 725D . Contest Balloons(贪心+优先队列)

    题目链接:codeforces 725D . Contest Balloons 先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给 ...

  6. Codeforces Round #322 (Div. 2) C. Developing Skills 优先队列

    C. Developing Skills Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  7. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)

    A. Carrot Cakes time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

  8. Educational Codeforces Round 62 (Rated for Div. 2) C 贪心 + 优先队列 + 反向处理

    https://codeforces.com/contest/1140/problem/C 题意 每首歌有\(t_i\)和\(b_i\)两个值,最多挑选m首歌,使得sum(\(t_i\))*min(\ ...

  9. Codeforces 1132D - Stressful Training - [二分+贪心+优先队列]

    题目链接:https://codeforces.com/contest/1132/problem/D 题意: 有 $n$ 个学生,他们的电脑有初始电量 $a[1 \sim n]$,他们的电脑每分钟会耗 ...

随机推荐

  1. Smallest Bounding Rectangle - uva10173

    Smallest Bounding Rectangle Given the Cartesian coordinates of n(>0)2-dimensional points, write a ...

  2. 初学画布canvas的chapter2

    文本 1.字体属性 context.font = [css font property] ——使用CSS规范,语法跟CSS字体速记符号一致 ——line-height无效,并永远忽略 Context. ...

  3. linux文件上传,给文件或目录添加apache权限

    系统环境:ubuntu11.10/apache2/php5.3.6 在LAMP环境中,测试一个简单的php文件上传功能时,发现/var/log/apache2/error.log中出现如下php警告: ...

  4. My favorite bit torrent client for Ubuntu

    Deluge Bit Torrent ClientDeluge is among my favorite bit torrent clients for Ubuntu. It is fast, sli ...

  5. 《BI项目笔记》创建父子维度

    创建步骤: 而ParentOriginID其实就是对应的ParentOriginID,它的 Usage 必须是 Parent 才能表示这样的一个父子维度. 查看OriginID属性, Usage 是 ...

  6. 协同过滤 CF & ALS 及在Spark上的实现

    使用Spark进行ALS编程的例子可以看:http://www.cnblogs.com/charlesblc/p/6165201.html ALS:alternating least squares ...

  7. HTTP状态码及其含义

    下表显示了常见的HTTP 1.1状态代码以及它们对应的状态信息和含义.应当谨慎地使用那些只有HTTP 1.1支持的状态代码,因为许多浏览器还只能够支持HTTP 1.0.如果你使用了HTTP 1.1特有 ...

  8. iOS沙盒路径的查看和使用

    1.模拟器沙盒目录 文件都在个人用户名文件夹下的一个隐藏文件夹里,中文叫资源库,他的目录其实是Library. 因为应用是在沙箱(sandbox)中的,在文件读写权限上受到限制,只能在几个目录下读写文 ...

  9. DbInitializer.cs初始化过程中context.entityName.Add()遇到的类型不匹配错误

    用Asp.Net Core+EF Core建立一个测试项目过程中,使用DbInitializaer.cs进行数据库表的初始化工作,当项目测试运行时执行到context.实体名.Add()时,提示错误信 ...

  10. 2-c语言作业

    #include<stdio.h> #include<math.h> int main(void) { int money,year; double rate,sum; pri ...