NC21573. 小乐乐玩木桶+
描述
输入描述
第一行输入整数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)