51Nod(1627)
来源:互联网 发布:windows高级选项菜单 编辑:程序博客网 时间:2024/06/06 19:12
贪心 区间技巧。
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<set>using namespace std;typedef long long ll;typedef pair<int,int > P;const int maxn = 100005;ll num[maxn];ll sum[maxn];P p[maxn];multiset<int>s;int main(){ int n,k,m,u,v; scanf("%d%d%d",&n,&k,&m); for(int i=1;i<=n;i++) scanf("%I64d",&num[i]); sum[0] = 0; for(int i=1;i<=n;i++) sum[i] = sum[i-1] + num[i]; for(int i=0;i<m;i++) { scanf("%d%d",&u,&v); p[i] = make_pair(u,v); } sort(p,p+m); multiset<int>::iterator it; ll ans = 0; for(int i=0;i<m;i++) { u = p[i].first; s.insert(p[i].second); while(s.size()) { if(*(s.begin())<u) s.erase(s.begin());else break; } while((int)s.size()>k) s.erase(s.begin()); if((int)s.size()==k) { ans = max(ans,sum[*s.begin()]-sum[u-1]); } } printf("%lld\n",ans); return 0;}
阅读全文
0 0
- 51Nod(1627)
- 51nod 1627 瞬间移动
- 51nod 1627 瞬间移动
- 51nod 1627 区间交
- 51Nod
- 51Nod
- 51nod
- 51Nod
- 51Nod
- 51Nod
- 51Nod
- 51Nod
- 51Nod
- 51Nod
- 51Nod
- 51Nod
- 51Nod
- 51Nod
- mybatis 详解(九)------ 一级缓存、二级缓存
- Maven笔记
- python如何调用c语言
- jQuery多图片上传同时带预览
- 51nod 1179 最大的公约数
- 51Nod(1627)
- Hibernate 5;org.hibernate.MappingException: Unknown entity: com.my.model.User
- django基础知识
- SVM分类器的实现(包括交叉验证选择参数,Dlib,可视化)
- 【机器学习入门】Andrew NG《Machine Learning》课程笔记之二 :基本概念、代价函数、梯度下降和线性回归
- C++退出函数exit
- USACO-2008-Cow Contest
- 最大子序列数,只测试了几组数据,求大佬指点
- 【SpringBoot】1.SpringBoot介绍