当前位置:网站首页>【暑期每日一题】洛谷 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;
}
边栏推荐
- Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and
- 神经网络-最大池化的使用
- 科研狗可能需要的一些工具
- The longest increasing subsequence and its optimal solution, total animal weight problem
- Common interview questions ①
- 对象的序列化与反序列化
- 数据加载及预处理
- 神经网络-使用Sequential搭建神经网络
- STM32扩展板 数码管显示
- This sideline workload is small, 10-15k, free unlimited massage
猜你喜欢
Neural network convolution layer
[godot] unity's animator is different from Godot's animplayer
Cmake selecting compilers and setting compiler options
Openresty rewrites the location of 302
How to use common datasets in pytorch
Common methods in transforms
Use of dataloader
Technology sharing | broadcast function design in integrated dispatching
[hard ten treasures] - 1 [basic knowledge] classification of power supply
Difficulties in the development of knowledge map & the importance of building industry knowledge map
随机推荐
1076 Forwards on Weibo
分布式全局唯一ID解决方案详解
缓冲流与转换流
Quelques outils dont les chiens scientifiques pourraient avoir besoin
Dataloader的使用
【硬十宝典】——1.【基础知识】电源的分类
STM32扩展版 按键扫描
Difference between cookie and session
How to view the changes and opportunities in the construction of smart cities?
STM32 光敏电阻传感器&两路AD采集
[hard ten treasures] - 1 [basic knowledge] classification of power supply
Codeforces Round #771 (Div. 2) ABCD|E
Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and
LeetCode_ 66 (plus one)
pytorch中常用数据集的使用方法
How to use maixll dock
[FTP] the solution to "227 entering passive mode" during FTP connection
解决qiankun中子应用外链文件无法获取
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
STM32 extended key scan