1337.cpp (628B)
1 class Solution { 2 public: 3 typedef pair<int, int> ii; 4 vector<int> kWeakestRows(vector<vector<int>> &mat, int k) { 5 vector<ii> vp; 6 7 int i = 0; 8 for (auto &v : mat) 9 vp.push_back(make_pair(i++, accumulate(v.begin(), v.end(), 0))); 10 11 sort(vp.begin(), vp.end(), [](const ii &a, const ii &b) -> bool { 12 return a.second < b.second || (a.second == b.second && a.first < b.first); 13 }); 14 15 vector<int> res; 16 for (auto &p : vp) 17 if (k--) 18 res.push_back(p.first); 19 else 20 break; 21 22 return res; 23 } 24 };