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 ...
随机推荐
- Maya2019下载安装与激活
目录 1. 更多推荐 2. 下载地址 2.1. OneDrive 2.2. Window (64位) 2.3. MAC_OSX 3. 安装激活教程 1. 更多推荐 其他Maya版本的下载与激活:htt ...
- C# List<object> 按特定字段排序
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...
- 使用C#解析XMIND文件格式
static void Main(string[] args) { var tempPath = @"c:\Temp"; if (Directory.Exists(tempPath ...
- process-hacker
https://github.com/processhacker/processhacker#process-hacker // begin_phapppub typedef enum _PH_KNO ...
- Redis分布式锁【实战】
概述 目前几乎很多大型网站及应用都是分布式部署的,分布式场景中的数据一致性问题一直是一个比较重要的话题.分布式的CAP理论告诉我们“任何一个分布式系统都无法同时满足一致性(Consistency).可 ...
- error: must use ‘class’ tag to refer to type ‘XXX’ in this scope
开发环境: Qt Creator 4.8.2 在写程序的时候,遇到了编译器报错 error: must use 'class' tag to refer to type 'XXX' in this s ...
- Ubuntu apt-get install E: 无法定位软件包Ubuntu apt-get install E: 无法定位软件包
sudo cp /etc/apt/sources.list /etc/apt/sources.list-bak #先将之前的source-list备份 sudo vi /etc/apt/sources ...
- 二叉树的下一个结点(剑指offer_8)
题目描述 给定一个二叉树和其中一个结点,请找出中序遍历顺序的下一个结点并返回.注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针. public class TreeLinkNode { i ...
- python类对象属性查找原理
class Foo(object): def __init__(self): # 这是一个对象属性 self.obj_pro = 12 # 这是一类属性 c_pro = 11 # 这是一个静态方法 @ ...
- 当执行一条查询语句时,MySQL内部经历了什么?
假如说我们有一张表 T ,表里只有一个字段 ID,当我们执行下边这条SQL语句时: mysql> select * fron T where ID=10; 在我们眼中能看到的只是输入一条 SQL ...