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\)个正方 ...
随机推荐
- UUID 和 GUID 的区别(转)
UUID是一个由4个连字号(-)将32个字节长的字符串分隔后生成的字符串,总共36个字节长.比如:550e8400-e29b-41d4-a716-446655440000 http://gohands ...
- codeforces 569D D. Symmetric and Transitive(bell数+dp)
题目链接: D. Symmetric and Transitive time limit per test 1.5 seconds memory limit per test 256 megabyte ...
- python multiprocessing多进程应用
multiprocessing包是Python中的多进程管理包,可以利用multiprocessing.Process对象来创建进程,Process对象拥有is_alive().join([timeo ...
- nginx开发_Filter模块执行顺序
Filter模块执行顺序 Filter模块的执行顺序是在执行configure文件时决定的,configure文件执行完成后生成objs/ngx_modules.c,文件中定义了一个数组ngx_mod ...
- AngularJS系统学习之Module(模块)
本文源自:http://blog.csdn.net/woxueliuyun/article/details/50962645 学习之后略有所得, 来此分享.建议看原文. 模块是提供一些特殊服务的功能块 ...
- const用在成员函数之后的情况
常成员函数 使用const关键字进行说明的成员函数,称为常成员函数.只有常成员函数才有资格操作常量或常对象,没有使用const关键字说明的成员函数不能用来操作常对象.常成员函数说明格式 ...
- sublime text3配置node.js环境,以及出现的问题
1) 下载sublime并安装,下载列表:https://www.sublimetext.com/3 2) 下载sublime的nodejs插件,需是集成Nodejs插件到sublime中,下载地址: ...
- HDOJ-2160
母猪的故事 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- sql语句之约束条件
not null约束,需设置默认值 sex enum('male','female') not null default 'male' unique 约束,值唯一 单列唯一: create table ...
- 洛谷P4151 [WC2011]最大XOR和路径(线性基)
传送门 不知道线性基是什么东西的可以看看蒟蒻的总结 首先看到异或就想到线性基 我们考虑有一条路径,那么从这条路径走到图中的任意一个环再走回这条路径上,对答案的贡献是这个环的异或和,走到这个环上的路径对 ...