【组队赛三】-D 优先队列 cf446B
DZY Loves Modification
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit
Status
Practice
CodeForces 446B
Description
As we know, DZY loves playing games. One day DZY decided to play with a n × m matrix. To be more precise, he decided to modify the matrix with exactly k operations.
Each modification is one of the following:
Pick some row of the matrix and decrease each element of the row by p. This operation brings to DZY the value of pleasure equal to the sum of elements of the row before the decreasing.
Pick some column of the matrix and decrease each element of the column by p. This operation brings to DZY the value of pleasure equal to the sum of elements of the column before the decreasing.
DZY wants to know: what is the largest total value of pleasure he could get after performing exactly k modifications? Please, help him to calculate this value.
Input
The first line contains four space-separated integers n, m, k and p(1 ≤ n, m ≤ 103; 1 ≤ k ≤ 106; 1 ≤ p ≤ 100).
Then n lines follow. Each of them contains m integers representing aij (1 ≤ aij ≤ 103) — the elements of the current row of the matrix.
Output
Output a single integer — the maximum possible total pleasure value DZY could get.
Sample Input
Input
2 2 2 2
1 3
2 4
Output
11
Input
2 2 5 2
1 3
2 4
Output
11
Hint
For the first sample test, we can modify: column 2, row 2. After that the matrix becomes:
1 1
0 0
For the second sample test, we can modify: column 2, row 2, row 1, column 1, column 2. After that the matrix becomes:
-3 -3
-2 -2
<span style="color:#3333ff;">/*
_______________________________________________________________________________________ author : Grant yuan
time : 2014.7.21
algorithm : priority_queue
explain : 首先对行和列在1到k的范围内分别求解,然后求出一个满足i和k-i的最大值,
注意终于的结果中减去反复计算的,还有会測试大于int类型的数据。
—————————————————————————————————————————————————————————————————————————————————————————
*/ #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<functional>
using namespace std;
#define INF 999999999; priority_queue<__int64>q1;
priority_queue<__int64>q2;
__int64 m,n,k,p,h;
__int64 a[1003][1003];
__int64 s1[1003],s2[1003];
__int64 sum1[1000003],sum2[1000003];
__int64 res,ans,hh; int main()
{
cin>>n>>m>>k>>p;
ans=INF;
ans=-ans*ans;
memset(s1,0,sizeof(s1));
memset(s2,0,sizeof(s2));
memset(sum1,0,sizeof(sum1));
memset(sum2,0,sizeof(sum2));
while(!q1.empty())
q1.pop();
while(!q2.empty())
q2.pop(); for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
scanf("%I64d",&a[i][j]);
s1[i]+=a[i][j];
s2[j]+=a[i][j];} for(int i=0;i<n;i++)
q1.push(s1[i]); for(int i=0;i<m;i++)
q2.push(s2[i]); for(int i=1;i<=k;i++)
{
h=q1.top();q1.pop();
if(i==1)sum1[i]=h;
else sum1[i]=sum1[i-1]+h;
h-=m*p;
q1.push(h);
}
for(int i=1;i<=k;i++)
{
h=q2.top();q2.pop();
if(i==1)sum2[i]=h;
else sum2[i]=sum2[i-1]+h;
h-=n*p;
q2.push(h);
} for(int i=0;i<=k;i++)
{
res=sum1[i]+sum2[k-i];
ans=max(ans,res-i*p*(k-i));
} cout<<ans<<endl;
return 0; }
</span>
【组队赛三】-D 优先队列 cf446B的更多相关文章
- 用C++的类做三种优先队列的实现
学过数据结构的都知道优先队列这种东西,普通的队列是依据入队顺序,先入队的先出队,而优先队列则是依照键值,键值越大(或越小),就越先出队. 所以,优先队列基本支持push,pop,empty,size, ...
- 【组队赛三】-C cf448B
Suffix Structures Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit S ...
- 暑假练习赛 004 E Joint Stacks(优先队列模拟)
Joint StacksCrawling in process... Crawling failed Time Limit:4000MS Memory Limit:65536KB 64 ...
- 51nod 1689 逛街(优先队列)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1689 题意: 题意: 枚举终点,这样就确定路上的花费,接下来只需要计算进 ...
- 2016 多校联赛7 Joint Stacks (优先队列)
A stack is a data structure in which all insertions and deletions of entries are made at one end, ca ...
- HDU 1103 Flo's Restaurant(模拟+优先队列)
Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 5818 Joint Stacks (优先队列)
Joint Stacks Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 【STL】栈+队列+优先队列(详)+ 拯救行动题解
一.栈 栈(stack)又名堆栈,它是一种运算受限的线性表.其限制是仅允许在表的一端进行插入和删除运算.这一端被称为栈顶,相对地,把另一端称为栈底.向一个栈插入新元素又称作进栈.入栈或压栈,它是把新元 ...
- 算法导论——lec 12 平摊分析与优先队列
在平摊分析中,运行一系列数据结构操作所须要的时间是通过对运行的全部操作求平均得出.反映在不论什么情况下(即最坏情况下),每一个操作具有平均性能.掌握了平摊分析主要有三种方法,聚集分析.记账方法.势能方 ...
随机推荐
- verilog语法实例学习(3)
Verilog 操作运算符 算术运算符 +,-,*,/,**(加/减/乘/除/幂运算),乘法运算的结果的位宽是乘数和被乘数位宽的和. 在进行整数的除法运算时,结果要略去小数部分,只取整数部分:而进行取 ...
- 样条之贝塞尔(Bezier)
我曾经发过两篇关于贝塞尔的文章:数学图形(1.47)贝塞尔(Bézier)曲线,数学图形之贝塞尔(Bézier)曲面.那是使用我自己定义的脚本语言生成贝塞尔图形.由于我自己定义的脚本语法功能有限,所以 ...
- 解决 win7 注册com组件失败问题
解决 win7 注册com组件失败问题 运行:regsvr32 xxx.ocx 提示:模块 "xxx.ocx" 已加载,但对调用 dllregisterserver 的调用失败,错 ...
- 基于双向LSTM和迁移学习的seq2seq核心实体识别
http://spaces.ac.cn/archives/3942/ 暑假期间做了一下百度和西安交大联合举办的核心实体识别竞赛,最终的结果还不错,遂记录一下.模型的效果不是最好的,但是胜在“端到端”, ...
- Android 与 js 简单互调
总结: Android 调用 js: 在 Android 中创建通往 javascript 的接口; 在 html 中定义要执行的方法; 在 Android 中的具体事件中进行调用. cont ...
- (转)在NGUI使用图片文字(数字、美术字)(直接可用于UILable)
本文永久地址:http://www.omuying.com/article/24.aspx,[文章转载请注明出处!] 在 Unity 开发过程中,我们经常会使用到美术提供的图片文字(数字)来美化我们的 ...
- Masonry自动布局使用
Masonry是一个轻量级的布局框架,采用更好的语法封装自动布局,它有自己的布局DSL.简洁明了并具有高可读性 而且同时支持 iOS 和 Max OS X. 下载 NSLayoutConstraint ...
- iOS的settings bundle中开关button(Toggle Switch)取不到值的问题
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 假设认为写的不好请多提意见,假设认为不错请多多支持点赞.谢谢! hopy ;) 在Xcode7.2中设置App的settings bundle ...
- 离线LCA学习
题目1 : 近期公共祖先·二 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描写叙述 上上回说到,小Hi和小Ho用很拙劣--或者说粗糙的手段山寨出了一个奇妙的站点,这个站点能 ...
- Android github XListView 分析(2-3)
本文内容 概述 XListView UML 图 下载 github XListView 概述 我们经常能见到 app 中的 listview 有"下拉更多"和"上拉加载& ...