当前位置:网站首页>[daily question in summer] first time, second time, deal!
[daily question in summer] first time, second time, deal!
2022-07-01 04:47:00 【AC_ Dragon】
Title Description
Because the diet exercise of cows gives FJ There's a lot of hay left that can't be handled , So he's going to open an auction to sell his hay .
He has n A batch of hay ( Each batch is about 100 bundle ). His clients are m individual , All the farmers next to him . The first i A farmer will tell FJ He will do it for FJ Pay for each batch of hay pi The money . Every farmer wants to buy ( I just want to buy )FJ A batch of forage .
To make sure farmers don't envy each other , therefore FJ Decided to sell his forage at a fixed price . Each bid is better than FJ Farmers who ask higher prices will buy forage , The rest will be rejected .
Please help FJ Find out the lowest price of a single batch of forage that can make him the most money .
Input format
first line : Two integers separated by spaces ,n and m.
Line two to line two m+1 That's ok : The first i+1 The line contains only one integer :pi.
Output format
All in one line , Contains two integers separated by spaces :FJ The lowest price of each batch of forage that can be offered , And the most money he can make .
Examples #1
The sample input #1
5 4
2
8
10
7Sample output #1
7 21Tips
FJ Yes 5 Batch forage ,4 A farmer wants to buy . Their bids are : Each batch of forage is 2,8,10 and 7.
FJ The price should be set to 7, There will be 3 A farmer will pay for forage ,FJ I'll earn it 21 The money .
---
about 100% The data of ,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;
}边栏推荐
- Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor
- Difficulties in the development of knowledge map & the importance of building industry knowledge map
- Pytorch(二) —— 激活函数、损失函数及其梯度
- 【暑期每日一题】洛谷 P7222 [RC-04] 信息学竞赛
- 解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *
- 【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
- Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
- 【暑期每日一题】洛谷 P5740【深基7.例9】最厉害的学生
- Extension fragment
- C - detailed explanation of operators and summary of use cases
猜你喜欢
随机推荐
2022 t elevator repair new version test questions and t elevator repair simulation test question bank
LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver
扩展-Fragment
Neural network convolution layer
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
How to use common datasets in pytorch
Use and modification of prior network model
STM32扩展版 按键扫描
pytorch 卷积操作
Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling
Dual contractual learning: text classification via label aware data augmentation reading notes
神经网络-最大池化的使用
C -- array
C - detailed explanation of operators and summary of use cases
【暑期每日一题】洛谷 P5740【深基7.例9】最厉害的学生
LeetCode_28(实现 strStr())
Overview of the construction details of Meizhou veterinary laboratory
常用的Transforms中的方法
Pytoch (II) -- activation function, loss function and its gradient
Shell之一键自动部署Redis任意版本








