当前位置:网站首页>【暑期每日一题】洛谷 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;
}边栏推荐
- 扩展-Fragment
- Matters behind the construction of paint testing laboratory
- 神经网络-卷积层
- LeetCode_53(最大子数组和)
- RuntimeError: mean(): input dtype should be either floating point or complex dtypes. Got Long instead
- 解决qiankun中子应用外链文件无法获取
- The junior college students were angry for 32 days, four rounds of interviews, five hours of soul torture, and won Ali's offer with tears
- Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor
- C -- array
- Why is Internet thinking not suitable for AI products?
猜你喜欢
![AssertionError assert I.ndim == 4 and I.shape[1] == 3](/img/b1/0109bb0f893eb4c8915df36c100907.png)
AssertionError assert I.ndim == 4 and I.shape[1] == 3

pytorch中常用数据集的使用方法

Pytorch(三) —— 函数优化

Neural networks - use of maximum pooling

Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom

神经网络-卷积层

Why is Internet thinking not suitable for AI products?

Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling

Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor

VR线上展览所具备应用及特色
随机推荐
LeetCode_ 35 (search insertion position)
Pytorch neural network construction template
JS to solve the problem of floating point multiplication precision loss
Shell analysis server log command collection
分布式数据库数据一致性的原理、与技术实现方案
字符输入流与字符输出流
Fitness without equipment
Neural network - nonlinear activation
【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
Applications and features of VR online exhibition
Difference between cookie and session
分布式-总结列表
The index is invalid
I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own
RuntimeError: mean(): input dtype should be either floating point or complex dtypes.Got Long instead
Take a cold bath
JVM栈和堆简介
js解决浮点数相乘精度丢失问题
科研狗可能需要的一些工具
Pytoch (I) -- basic grammar