-
Notifications
You must be signed in to change notification settings - Fork 10
/
token.cpp
34 lines (32 loc) · 807 Bytes
/
token.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
class Solution {
public:
int bagOfTokensScore(vector<int>& t, int pow) {
int ans = 0;
int score = 0;
sort(t.begin(),t.end());
int i=0, j=t.size()-1;
while(i<=j){
if(pow>=t[i]){
cout<<"score up"<<endl;
pow-=t[i];
score++;
ans = max(ans, score);
i++;
}
else if(score>=1){
cout<<"score down"<<endl;
pow+=t[j];
score--;
ans = max(ans, score);
j--;
}
else
return ans;
}
return ans;
}
};
//score more
//power less
//pow<token i -- lose token power // gain 1 score
//score>=1 -- gain token power // lose 1 score