-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathE0076.cpp
More file actions
37 lines (33 loc) · 716 Bytes
/
E0076.cpp
File metadata and controls
37 lines (33 loc) · 716 Bytes
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
/*
Problem Statement: https://www.hackerrank.com/challenges/luck-balance/problem
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int luckBalance(int k, vector< vector<int> > contests) {
int luck = 0;
sort(contests.rbegin(), contests.rend());
for (int i = 0; i < contests.size(); i++) {
if (!contests[i][1])
luck += contests[i][0];
else {
if (k != 0) {
luck += contests[i][0];
k--;
}
else
luck -= contests[i][0];
}
}
return luck;
}
int main() {
int n, k;
cin >> n >> k;
vector< vector<int> > contests(n, vector<int>(2));
for (int i = 0; i < n; i++)
cin >> contests[i][0] >> contests[i][1];
cout << luckBalance(k, contests);
return 0;
}