水题感觉就是好。
当我写sort的时候,心里想,千万不要忘记加头文件。。。当我点了提交后,猛一想!头文件忘加了 T T。。。
AC后,怎么想着不用sort试试,无情地WA了,真是脑子进水了 = =。。。
这题求不让绳子断的最大重量。有的绳子可以不用。。。
所以从小到大排除k小的,每排除一次算一次总重量即可。
不能直接算中间的,很容易举反例,比如9,10,20 。算10的话 就没有9了,而9*3 > 10*2
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <queue>
#include <limits.h>
#include <algorithm>
using namespace std;
int main()
{
int t[1001];
int ncases,n,i;
scanf("%d",&ncases);
while( ncases-- )
{
scanf("%d",&n);
for(i=0; i<n; i++)
scanf("%d",&t[i]);
sort(t,t+n);
int max = 0;
for(i=0; i<n; i++)
if( t[i] * (n-i) > max )
max = t[i]*(n-i);
printf("%d/n",max);
}
return 0;
}