2971.cpp (326B)
1 class Solution { 2 public: 3 long long largestPerimeter(vector<int> &nums) const { 4 sort(begin(nums), end(nums)); 5 6 long long res = -1, crnt = 0; 7 for (int i = 0; i < size(nums); i++) { 8 crnt += nums[i]; 9 if (crnt > nums[i] * 2) res = crnt; 10 } 11 12 return res; 13 } 14 };