-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigital_wallet.cpp
More file actions
79 lines (69 loc) · 1.58 KB
/
Digital_wallet.cpp
File metadata and controls
79 lines (69 loc) · 1.58 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define el cout << "\n";
#define pii pair<int, int>
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define vi vector<int>
#define vii vector<pair<int, int>>
bool cmp(const pii &a, const pii &b)
{
if (a.first != b.first)
return (a.first > b.first);
else
return (a.second < b.second);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int r, c, k;
cin >> r >> c >> k;
int arr[r][c];
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
cin >> arr[i][j];
}
}
int brr[c] = {0};
vi p;
for (int i = 0; i < c; i++)
{
vii v1;
for (int j = 0; j < r; j++)
{
v1.push_back({arr[j][i], j});
}
sort(v1.begin(), v1.end(), cmp);
brr[i] = v1[0].first;
p.push_back(v1[0].second);
}
int sum = 0;
for (int i = 0; i < c - k + 1; i++)
{
vii v;
for (int j = i; j <= i + k - 1; j++)
{
v.push_back({brr[j], j});
}
sort(v.begin(), v.end(), cmp);
sum += v[0].first;
arr[p[v[0].second]][v[0].second] = 0;
vii v1;
int y = v[0].second;
for (int j = 0; j < r; j++)
{
v1.push_back({arr[j][y], j});
}
sort(v1.begin(), v1.end(), cmp);
brr[y] = v1[0].first;
p[v[0].second] = v1[0].second;
}
cout << sum;
return 0;
}