-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaximum_expenditure.cpp
61 lines (59 loc) · 1.31 KB
/
maximum_expenditure.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
static const int __ = []() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
return 0;
}();
class Solution {
public:
long long maxSpending(vector<vector<int>> &values) {
int i, j;
// cout<<values.length();
int n = values.size();
int m = values[i].size();
long long result;
int count = 0;
// int result;
int sum = 0;
vector<int> arr;
// vector<int> sums;
int k, num;
int skip;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
arr.push_back(values[i][j]);
}
}
sort(arr.begin(), arr.end());
// for(i=0; i<arr.size(); i++){
// cout<<arr[i]<<endl;
// }
for (i = 0; i < arr.size(); i++) {
count = arr[i];
skip = 0;
for (j = 0; j < n; j++) {
for (k = 0; k < m; k++) {
if (values[j][k] == count) {
// cout<<values[j][k]<<endl;
num = values[j][k] * (i + 1);
sum = sum + num;
// sums.push_back(num);
skip = 1;
break;
} else {
continue;
}
}
if (skip == 1) {
break;
}
}
}
// for(i=0; i<sums.size(); i++){
// // cout<<sums[i]<<endl;
// sum = sum + sums[i];
// }
result = sum;
return result;
}
};