-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2300.cpp
More file actions
43 lines (37 loc) · 1.04 KB
/
2300.cpp
File metadata and controls
43 lines (37 loc) · 1.04 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
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {
const int m = spells.size(), n = potions.size();
sort(potions.begin(), potions.end());
vector<int> result;
for(int num : spells) {
int pos = binary(potions, num, success);
if((long long) numpotions[pos] >= success) {
result.push_back(n - pos);
}
else {
result.push_back(0);
}
}
return result;
}
int binary(vector<int>& potions, long long num, long long success) {
int left = 0, right = potions.size() - 1;
while(left < right) {
int mid = left + ((right - left) >> 1);
if(numpotions[mid] >= success) {
right = mid;
}
else {
left = mid + 1;
}
}
return left;
}
};
int main() {
Solution solution;
return 0;
}