#include<iostream> #include<vector> #include<algorithm> #include<iomanip> #include<string> #include<cmath> using namespace std; //void dfs(vector<int>& cords, int pos, vector<int>& temp) { // // if (temp.size() > 0) { // // if (temp[0] * temp.size() > res) // res = temp[0] * temp.size(); // } // // if (pos == cords.size()) // return; // // for (int i = pos; i < cords.size(); i++) { // // temp.push_back(cords[i]); // // dfs(cords, i + 1, temp); // // temp.pop_back(); // } //} int main() { int T; cin >> T; for (int i = 0; i < T; i++) { int n; cin >> n; vector<int> cords(n); for (int j = 0; j < n; j++) cin >> cords[j]; sort(cords.begin(), cords.end()); int res = 0; for (int i = 0; i < cords.size(); i++) { int temp = cords[i] * (cords.size() - i); //当前绳子在所有组合中的最大承受重量 res = max(res, temp); } cout << res << endl; } } |
Double click to view unformatted code.