当前位置:网站首页>【暑期每日一题】洛谷 P2637 第一次,第二次,成交!
【暑期每日一题】洛谷 P2637 第一次,第二次,成交!
2022-07-01 04:47:00 【AC_Dragon】
题目链接:P2637 第一次,第二次,成交! - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
题目描述
因为奶牛们的节食运动给 FJ 余下了一大批干草无法处理,所以他准备要开一个拍卖会去出售他的干草。
他有 n 批干草(每批大约 100 捆)。他的客户有 m 个,都是和他相邻的农夫。第 i 名农夫会告诉 FJ 他会为 FJ 的每批干草付 pi 的钱。每个农夫都想买(也只想买)FJ 的一批草料。
为了确保农夫们不会互相嫉妒,所以 FJ 决定要以一个固定的价格出售他的草料。每一个出价比 FJ 的要价要高的农夫将会买到草料,余下的将会被拒绝购买。
请你帮助 FJ 找出能让他赚到最多的钱的最低的单批草料的售价。
输入格式
第一行:两个被空格隔开的整数,n 和 m。
第二行到第 m+1 行:第 i+1 行只包含一个整数:pi。
输出格式
共一行,包含由空格隔开的两个整数:FJ 能出的每批草料的最低价格,以及他能赚到的最多的钱。
样例 #1
样例输入 #1
5 4
2
8
10
7样例输出 #1
7 21提示
FJ 有 5 批草料,4 个农夫想要购买。他们出价分别为:每批草料为 2,8,10 和 7。
FJ 应该把价格设定为 7,这样会有 3 个农夫会付钱买草料,FJ 自己会挣到 21 的钱。
---
对于 100% 的数据,1<= n <= 1000,1<= m <= 1000,1<= pi <= 1,000,000。
AC code:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int a[m];
for(int i=0;i<m;i++)
cin>>a[i];
sort(a,a+m);
int res=0;
int r;
for(int i=0;i<m;i++)
{
if(a[i]*(m-i)>res)
r=a[i];
if((m-i)<=n)
res=max(a[i]*(m-i),res);
else
res=max(a[i]*n,res);
}
cout<<r<<" "<<res;
return 0;
}边栏推荐
- 技术分享| 融合调度中的广播功能设计
- 2022 hoisting machinery command registration examination and hoisting machinery command examination registration
- 2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank
- STM32 光敏电阻传感器&两路AD采集
- LeetCode_28(实现 strStr())
- How to view the changes and opportunities in the construction of smart cities?
- Leecode record 1351 negative numbers in statistical ordered matrix
- Difficulties in the development of knowledge map & the importance of building industry knowledge map
- Difference between cookie and session
- Simple implementation of slf4j
猜你喜欢

About the transmission pipeline of stage in spark
![解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *](/img/88/0b99d1db2cdc70ab72d2b3c623dfaa.jpg)
解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *

Use and modification of prior network model

VIM简易使用教程

扩展-Fragment

I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own

Maixll dock quick start

Pytoch (IV) -- visual tool visdom
![AssertionError assert I.ndim == 4 and I.shape[1] == 3](/img/b1/0109bb0f893eb4c8915df36c100907.png)
AssertionError assert I.ndim == 4 and I.shape[1] == 3

Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
随机推荐
STM32扩展板 温度传感器和温湿度传感器的使用
Difficulties in the development of knowledge map & the importance of building industry knowledge map
STM32 photoresistor sensor & two channel AD acquisition
Thoughts on the construction of Meizhou cell room
对象的序列化与反序列化
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
[hardware ten treasures catalogue] - reprinted from "hardware 100000 whys" (under continuous update ~ ~)
LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
STM32扩展版 按键扫描
Construction of Meizhou nursing laboratory: equipment configuration
Summary of acl2021 information extraction related papers
无器械健身
RuntimeError: mean(): input dtype should be either floating point or complex dtypes. Got Long instead
科研狗可能需要的一些工具
测量三相永磁同步电机的交轴直轴电感
Basic exercise of test questions hexadecimal to decimal
分布式架构系统拆分原则、需求、微服务拆分步骤
线程安全问题
Caijing 365 stock internal reference | the first IPO of Beijing stock exchange; the subsidiary of the recommended securities firm for gambling and gambling, with a 40% discount
FileOutPutStream