-
Notifications
You must be signed in to change notification settings - Fork 4
/
cocochanel.cpp
executable file
·53 lines (41 loc) · 1.1 KB
/
cocochanel.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using std::vector;
size_t getStartPos(unsigned cocos, const vector<unsigned> &gaini) {
using std::upper_bound;
return upper_bound(gaini.begin(), gaini.end(), cocos-1) - gaini.begin();
}
unsigned nrPrietene(unsigned cocos, const vector<unsigned> &gaini) {
unsigned prietene = 0;
for (size_t i = getStartPos(cocos, gaini); i < gaini.size(); ++i) {
if (cocos <= gaini[i]) {
cocos*=2;
prietene++;
}
}
return prietene;
}
int main() {
using std::ifstream;
ifstream in("cocochanel.in");
size_t nCocosi, nGaini;
in >> nCocosi >> nGaini;
vector<unsigned> cocosi(nCocosi);
vector<unsigned> gaini(nGaini);
for (unsigned &cocos:cocosi) {
in >> cocos;
}
for (unsigned &gaina:gaini) {
in >> gaina;
}
using std::sort;
sort(gaini.begin(), gaini.end());
using std::ofstream;
ofstream out("cocochanel.out");
for(const unsigned &cocos:cocosi) {
out << nrPrietene(cocos, gaini) << '\n';
}
return 0;
}