leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2931.cpp (533B)


      1 class Solution {
      2   public:
      3     long long maxSpending(const vector<vector<int>> &values) const {
      4         const int n = size(values), m = size(values[0]);
      5         long long res = 0, add = 0;
      6         static int vec[100001];
      7 
      8         for (int i = 0; i < n; i++) {
      9             for (int j = 0; j < m; j++) {
     10                 vec[m * i + j] = values[i][j];
     11             }
     12         }
     13 
     14         sort(vec, vec + n * m, greater());
     15         for (int i = 0; i < n * m; i++) {
     16             res += add += vec[i];
     17         }
     18 
     19         return res;
     20     }
     21 };