ZOJ-2488 Rotten Ropes

对每个绳子(承受力n)找出比它承受力大的绳子的个数m,则棍子重量 = n * m, 求出最大值即可.

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <climits>

using namespace std;

int num[1005];
int main()
{
   // freopen("in.txt", "r", stdin);
    int t;

    cin >> t;
    while(t--)
    {
        int n;

        cin >> n;
        for(int i = 0; i < n; i++)
            cin >> num[i];
        sort(num, num+n);

        int maxs = 0;
        for(int i = 0; i < n; i++)
        {
            maxs = max(maxs, (n-i)*num[i]);
        }
        cout << maxs << endl;
    }
    return 0;
}

你可能感兴趣的:(ZOJ-2488 Rotten Ropes)