View Code of Problem 61

#include <iostream>
#include "set"
#include "functional"

using namespace std;

/**
 * kkmd66 四刷
 * @return
 */

int main() {

    //t个测试案例
    int t;
    cin >> t;
    while (t--) {
        //n个绳子
        int n;
        cin >> n;
        //存储
        multiset<int, greater_equal<int>> weight;
        for (int i = 0; i < n; ++i) {
            int temp;
            cin >> temp;
            weight.insert(temp);
        }
        //找最大承受重量
        int max, count = 0;
        for (auto it: weight) {
            if (count == 0)
                max = it;
            if (count > 0) {
                if (it * (count + 1) > max)
                    max = it * (count + 1);
            }
            count++;
        }
        //输出
        cout << max << endl;
    }

    return 0;
}

Double click to view unformatted code.


Back to problem 61