-
Notifications
You must be signed in to change notification settings - Fork 0
/
11jun.txt
52 lines (52 loc) · 1.43 KB
/
11jun.txt
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
class Solution {
public:
long long maxTip(int n, int x, int y, vector<int> &arr, vector<int> &brr) {
// code here
vector<pair<long long, int>> tip_diff;
long long tipA = 0;
long long tipB = 0;
int maxServeA = x;
int maxServeB = y;
for(int i = 0 ; i < n; i++)
{
long long diff = abs(arr[i] - brr[i]);
tip_diff.push_back(pair<long long , int>(diff, i));
}
sort(tip_diff.begin(), tip_diff.end(), greater<pair<long long, int>>());
/*for (auto x : tip_diff)
{
cout<< x.first<<" - "<<x.second<<endl;
}*/
for (auto a: tip_diff)
{
if (maxServeA > 0 && maxServeB > 0)
{
if (arr[a.second]>=brr[a.second])
{
tipA += arr[a.second];
maxServeA--;
}
else if(maxServeB > 0)
{
tipB += brr[a.second];
maxServeB--;
}
}
else if (maxServeB > 0)
{
tipB += brr[a.second];
maxServeB--;
}
else if (maxServeA > 0)
{
tipA += arr[a.second];
maxServeA--;
}
else
{
break;
}
}
return (long long) tipA+tipB;
}
};