H Kuangyeye and hamburgers
链接:https://ac.nowcoder.com/acm/contest/338/H
来源:牛客网
题目描述
输入描述:
the first line of input contains two integer n and k--the number of hamburgers on the counter and the number of plans Kuangyeye had;
the next line contains n integer--the i-th integer represents the weight of i-th hamburger,namely w
i
;
Each the following k line contains two integer a
i
and b
i
,represents Kuangyeye's strategy in his i-th plan.
输出描述:
Output contain a single integer,represents maximum weight of hamburgers Kuangyeye can eat.
备注:
1≤n,k≤100000,1≤a
i
≤b
i
≤n,1≤w
i
≤10000
题解:排序,计算前缀和,模拟
#include <iostream>
#include <algorithm>
using namespace std;
int w[100050];
long long dp[100050]; bool cmp(const int& a,const int& b) {
return a>b;
} int main() {
int n,k;
long long ans=0;
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>w[i];
sort(w+1,w+n+1,cmp);
dp[0]=0;
for(int i=1;i<=n;i++) {
dp[i]=dp[i-1]+w[i];
}
while(k--) {
int l,r;
cin>>l>>r;
ans=max(dp[r]-dp[l-1],ans);
}
cout<<ans<<endl;
return 0;
}
H Kuangyeye and hamburgers的更多相关文章
- 【哈希表】Ural Championship April 30, 2017 Problem H. Hamburgers
题意:有n群人,每个人有喜欢的汉堡配方:有m家店,给出每家店的每个汉堡的配方,如果存在某个汉堡,其配料表包含某个人喜欢的配方,则这个人喜欢这个汉堡所在的店家.问你对每群人,输出被喜欢的人数最多的店面是 ...
- Codeforces Round #218 (Div. 2) C. Hamburgers
C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- B - Hamburgers
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own han ...
- Codeforces 371C Hamburgers (二分答案)
题目链接 Hamburgers 二分答案,贪心判断即可. #include <bits/stdc++.h> using namespace std; #define REP(i,n) fo ...
- C. Hamburgers
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own han ...
- APUE中fcntl.h的使用及O_SYNC在Mac与Ubuntu下的测试
此部分测试涉及到APUE V3中,第三章的图3-12到图3-14. 通过fcntl.h提供的功能,修改fd的文件属性,本处增加O_SYNC功能,并测试其效果. 本文涉及代码: tree ch3 ch3 ...
- 关于apue.3e中apue.h的使用
关于apue.3e中apue.h的使用 近来要学一遍APUE第三版,并于此开博做为记录. 先下载源文件: # url: http://http//www.apuebook.com/code3e.htm ...
- YYModel 源码解读(二)之NSObject+YYModel.h (1)
本篇文章主要介绍 _YYModelPropertyMeta 前边的内容 首先先解释一下前边的辅助函数和枚举变量,在写一个功能的时候,这些辅助的东西可能不是一开始就能想出来的,应该是在后续的编码过程中 ...
- YYModel 源码解读(一)之YYModel.h
#if __has_include(<YYModel/YYModel.h>) FOUNDATION_EXPORT double YYModelVersionNumber; FOUNDATI ...
随机推荐
- C++ 编译器的安装(MinGW)
GNU GNU是一个自由软件工程项目,GNU工程已经开发了一个被称为“GNU”(GNU是“不是UNIX”的缩写)的.对Unix向上兼容的完整的自由软件系统(free software system). ...
- nginx+flask+gevent+uwsgi实现websocket
Websocket简介 WebSocket是HTML5开始提供的一种在单个 TCP 连接上进行全双工通讯的协议.在WebSocket API中,浏览器和服务器只需要做一个握手的动作,然后,浏览器和服务 ...
- [APIO2009]抢掠计划(Tarjan,SPFA)
[APIO2009]抢掠计划 题目描述 Siruseri 城中的道路都是单向的.不同的道路由路口连接.按照法律的规定, 在每个路口都设立了一个 Siruseri 银行的 ATM 取款机.令人奇怪的是, ...
- sqlmap 基本使用步骤(一)
列出数据据信息:python sqlmap.py -u "http://ctf5.shiyanbar.com/web/index_3.php?id=1" --dbs 列出当前数据库 ...
- Wannafly挑战赛27 D绿魔法师
链接Wannafly挑战赛27 D绿魔法师 一个空的可重集合\(S\),\(n\)次操作,每次操作给出\(x,k,p\),要求支持下列操作: 1.在\(S\)中加入\(x\). 2.求\[\sum_{ ...
- windows cmd bat处理文件
bat中输入: @echo offtitle 正在承载无线网络....netsh wlan start hostednetworknetsh wlan show hostednetworkecho 启 ...
- Python PEP8代码书写规范
摘自: 规范 https://blog.csdn.net/ratsniper/article/details/78954852
- window.onload()和$(document).ready的区别( $(document).ready == $(function(){ }) )
首先$(function(){}) 和 $(document).ready(function(){}) 是一个方法,$(function(){})为简写(用的多) $(document).ready和 ...
- MySQL WAL
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11447794.html WAL: Write-Ahead Logging 先写日志,再写磁盘.具体说, ...
- Android之SAX解析笔记
books.xml: <?xml version="1.0" encoding="utf-8"?> <books> <book i ...