列表

详情


NC21573. 小乐乐玩木桶+

描述

小乐乐用散落在森林里的木板做了一个木桶。
已知底面积为S()。
小乐乐经过各种仪器的精密测量知道了,所有木板的近似长度h[i]。
小乐乐只能选用三块木板去拼木桶,小乐乐拼凑成的木桶的最大装水体积是()?
(容量测量,底面积乘高,木桶不倾斜)

输入描述

第一行输入整数n,S。(3<=n<=1000,1<=s<=1000,n表示拼凑木桶所需木板)

第二行输入n个整数h[i](1<=h[i]<=1000,h[i]表示i号木板的长度)

输出描述

输出木桶最大装水体积。

示例1

输入:

3 3
2 3 4

输出:

6

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++11(clang++ 3.9) 解法, 执行用时: 3ms, 内存消耗: 376K, 提交时间: 2020-09-27 14:54:25

#include<bits/stdc++.h>
using namespace std;
int n,s,h[1005];
int main()
{
	cin>>n>>s;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	sort(h+1,h+1+n);
	cout<<h[n-2]*s<<endl;
	return 0;
}

Python3(3.5.2) 解法, 执行用时: 41ms, 内存消耗: 3556K, 提交时间: 2019-03-03 17:15:14

n,m = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
print(l[-3]*m)

上一题