Gym - 101810A ACM International Collegiate Programming Contest (2018)
bryce1010模板
http://codeforces.com/gym/101810/problem/A
大模拟,写崩了,代码借队友的。。。。。。
注意处理段与段的连接问题:
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
struct node{
long long l,r,val;
node(){}
node(long long ll,long long rr,long long vval)
{
l=ll;
r=rr;
val=vval;
}
}ar[maxn];
bool cmp(node a,node b)
{
return a.l<b.l;
}
int main(){
int t,m;
long long k;
scanf("%d",&t);
while(t--)
{
scanf("%d%lld",&m,&k);
int u,v,cost;
for(int i=0;i<m;i++)
{
scanf("%d%d%d",&u,&v,&cost);
ar[i]=node(u,v,cost);
}
sort(ar,ar+m,cmp);
long long sum=0,ans=0;
int pre=0;
for(int i=0;i<m;)
{
if(ar[i].r-ar[pre].l+1<=k)
{
sum+=(ar[i].r-ar[i].l+1)*ar[i].val;
ans=max(ans,sum);
i++;
}
else
{
if(ar[i].l-ar[pre].l>=k)
{
if(ar[i].r-ar[pre].r<=k)
{
ans=max(ans,sum+(ar[i].r-ar[i].l+1)*ar[i].val-(ar[i].r-ar[pre].l+1-k)*ar[pre].val);
sum+=(ar[i].r-ar[i].l+1)*ar[i].val;
i++;
}
else
{
sum-=(ar[pre].r-ar[pre].l+1)*ar[pre].val;
pre++;
}
}
else
{
ans=max(ans,sum+(k-ar[i].l+ar[pre].l)*ar[i].val);
if(ar[i].r-ar[pre].r<k)
{
sum+=(ar[i].r-ar[i].l+1)*ar[i].val;
ans=max(ans,sum-(ar[i].r-ar[pre].l+1-k)*ar[pre].val);
i++;
}
else
{
sum-=(ar[pre].r-ar[pre].l+1)*ar[pre].val;
pre++;
}
}
}
}
printf("%lld\n",ans);
}
return 0;
}
Gym - 101810A ACM International Collegiate Programming Contest (2018)的更多相关文章
- Gym - 101810H ACM International Collegiate Programming Contest (2018)
bryce1010模板 http://codeforces.com/gym/101810 #include <bits/stdc++.h> using namespace std; #de ...
- Gym - 101810F ACM International Collegiate Programming Contest (2018)
bryce1010模板 http://codeforces.com/gym/101810 #include<bits/stdc++.h> using namespace std; #def ...
- Gym - 101810E ACM International Collegiate Programming Contest (2018)
bryce1010模板 http://codeforces.com/gym/101810 #include<bits/stdc++.h> using namespace std; #def ...
- Gym - 101810D ACM International Collegiate Programming Contest (2018)
bryce1010模板 http://codeforces.com/gym/101810 #include <bits/stdc++.h> using namespace std; #de ...
- Gym - 101810C ACM International Collegiate Programming Contest (2018)
bryce1010模板 http://codeforces.com/gym/101810 #include <bits/stdc++.h> using namespace std; #de ...
- Gym - 101810B ACM International Collegiate Programming Contest (2018)
bryce1010模板 http://codeforces.com/gym/101810 #include <bits/stdc++.h> using namespace std; #de ...
- ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018
ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syr ...
- ACM International Collegiate Programming Contest World Finals 2014
ACM International Collegiate Programming Contest World Finals 2014 A - Baggage 题目描述:有\(2n\)个字符摆在编号为\ ...
- ACM International Collegiate Programming Contest World Finals 2013
ACM International Collegiate Programming Contest World Finals 2013 A - Self-Assembly 题目描述:给出\(n\)个正方 ...
随机推荐
- jvm调试
https://www.usenix.org/legacy/events/jvm01/full_papers/russell/russell_html/index.html
- 【USACO OPEN 10】hop
奶牛们正在回味童年,玩一个类似跳格子的游戏,在这个游戏里,奶牛们在草地上画了一行N个格子,(3 <=N <= 250,000),编号为1..N. 就像任何一个好游戏一样,这样的跳格子游戏也 ...
- BZOJ 2002 Bounce 弹飞绵羊 —— 分块算法
题目链接:https://vjudge.net/problem/HYSBZ-2002 2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec Memory Li ...
- GDP与股市市值
巴菲特提出一个判断市场估值高低的原则:市场总市值与GDP之比的高低,反映了市场投资机会和风险度.如果所有上市公司总市值占GDP的比率在70%-80%之间,则买入股票长期而言可能会让投资者有相当不错的报 ...
- BZOJ 1633 [Usaco2007 Feb]The Cow Lexicon 牛的词典:dp【删字符最少】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1633 题意: 给你一个长度为n的主串a,和一个有m个字符串s[i]的单词书(s[i].si ...
- Swift扩展
Swift中的「扩展」(extensions)和OC中的categories类似,只是Swift中的「扩展」没有名字.Swift中的「扩展」可以向一个已有的类/结构体/枚举类型添加新功能,这包括在没有 ...
- 基于候选区域的R-CNN系列网络简介
使用候选区域方法(region proposal method)创建目标检测的感兴趣区域(ROI).在选择性搜索(selective search,SS)中,首先将每个像素作为一组.然后,计算每一组的 ...
- PTA 哈希查找 除留取余法
PTA 电话聊天狂人(25 分) 给定大量手机用户通话记录,找出其中通话次数最多的聊天狂人. 输入格式: 输入首先给出正整数N(≤105),为通话记录条数.随后N行,每行给出一条通话记录.简单起 ...
- React.js:template
ylbtech-React.js: 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处:http://ylbtec ...
- 二、myeclipse中配置mybatis中xml的自动提示
以mybatis中mapper.xml为例 方法一: 步骤一:在mybatis-3.3.0.jar包中寻找mybatis-3-mapper.dtd文件. 可以用360压缩打开mybatis-3.3.0 ...