output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
long long n, k;
void solve() {
cin >> n >> k;
vector<int> p(n + 1), dup(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> p[i];
dup[i] = p[i];
}
while (k--) {
int l, r, x;
cin >> l >> r >> x;
int px = p[x];
int cnt = 0;
for (int i = l; i <= r; i++) {
if (px > p[i]) cnt++;
}
int now = l + cnt;
if (px == p[now])
cout << "Yes\n";
else
cout << "No\n";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, k;
void solve() {
cin >> n >> k;
vector<int> p(n + 1), dup(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> p[i];
dup[i] = p[i];
}
while (k--) {
int l, r, x;
cin >> l >> r >> x;
int px = p[x];
int cnt = 0;
for (int i = l; i <= r; i++) {
if (px > p[i]) cnt++;
}
int now = l + cnt;
if (px == p[now])
cout << "Yes\n";
else
cout << "No\n";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int p[10005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
for (int i = 1; i <= m; i++) {
int l, r, x, c = 0;
cin >> l >> r >> x;
for (int j = l; j <= r; j++) {
if (p[j] < p[x]) {
c++;
}
}
if (l + c == x) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
int p[10005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
for (int i = 1; i <= m; i++) {
int l, r, x, c = 0;
cin >> l >> r >> x;
for (int j = l; j <= r; j++) {
if (p[j] < p[x]) {
c++;
}
}
if (l + c == x) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
long n, m;
long a[10010], idx[10010];
long l, r, x, cnt;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
idx[a[i]] = i;
}
for (int i = 1; i <= m; i++) {
cin >> l >> r >> x;
cnt = 0;
for (int j = 1; j < a[x]; j++)
if ((idx[j] >= l) && (idx[j] <= r)) cnt += 1;
if ((l + cnt) == x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long n, m;
long a[10010], idx[10010];
long l, r, x, cnt;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
idx[a[i]] = i;
}
for (int i = 1; i <= m; i++) {
cin >> l >> r >> x;
cnt = 0;
for (int j = 1; j < a[x]; j++)
if ((idx[j] >= l) && (idx[j] <= r)) cnt += 1;
if ((l + cnt) == x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int x;
cin >> x;
return x;
}
int perm[10000];
int main() {
ios::sync_with_stdio(false);
int n = in(), m = in();
for (int i = 0; i < n; i++) perm[i] = in();
for (int i = 0; i < m; i++) {
int l = in(), r = in(), x = in(), count = 0;
for (int j = l - 1; j <= r - 1; j++) {
if (perm[j] < perm[x - 1]) count++;
}
if ((l + count) == x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int x;
cin >> x;
return x;
}
int perm[10000];
int main() {
ios::sync_with_stdio(false);
int n = in(), m = in();
for (int i = 0; i < n; i++) perm[i] = in();
for (int i = 0; i < m; i++) {
int l = in(), r = in(), x = in(), count = 0;
for (int j = l - 1; j <= r - 1; j++) {
if (perm[j] < perm[x - 1]) count++;
}
if ((l + count) == x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 2 * 1e18;
const int mod = 1e9 + 7;
const int maxn = 300005;
int n, m;
vector<int> arr;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
arr.resize(n + 1, 0);
for (int i = 1; i <= n; ++i) cin >> arr[i];
for (int i = 1; i <= m; ++i) {
int l, r, x;
cin >> l >> r >> x;
if (x < l || x > r)
cout << "Yes";
else {
int pos = 0;
for (int j = l; j <= r; ++j)
if (arr[j] < arr[x]) pos += 1;
if (l + pos == x)
cout << "Yes";
else
cout << "No";
}
cout << endl;
}
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = 2 * 1e18;
const int mod = 1e9 + 7;
const int maxn = 300005;
int n, m;
vector<int> arr;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
arr.resize(n + 1, 0);
for (int i = 1; i <= n; ++i) cin >> arr[i];
for (int i = 1; i <= m; ++i) {
int l, r, x;
cin >> l >> r >> x;
if (x < l || x > r)
cout << "Yes";
else {
int pos = 0;
for (int j = l; j <= r; ++j)
if (arr[j] < arr[x]) pos += 1;
if (l + pos == x)
cout << "Yes";
else
cout << "No";
}
cout << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[n], i, x, y, k, j, z, count = 0;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < m; i++) {
cin >> x >> y >> z;
x--;
y--;
z--;
k = a[z];
for (j = x; j <= y; j++) {
if (k > a[j]) count++;
}
if ((x + count) == z)
cout << "Yes\n";
else
cout << "No\n";
count = 0;
}
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[n], i, x, y, k, j, z, count = 0;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < m; i++) {
cin >> x >> y >> z;
x--;
y--;
z--;
k = a[z];
for (j = x; j <= y; j++) {
if (k > a[j]) count++;
}
if ((x + count) == z)
cout << "Yes\n";
else
cout << "No\n";
count = 0;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> p(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
}
int l, r, x;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
int less = 0;
for (int j = l - 1; j < r; j++) {
if (p[j] <= p[x - 1]) less++;
}
if (less == (x - l + 1))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> p(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
}
int l, r, x;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
int less = 0;
for (int j = l - 1; j < r; j++) {
if (p[j] <= p[x - 1]) less++;
}
if (less == (x - l + 1))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void init() {}
int main() {
init();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n, m;
cin >> n >> m;
long long int a[n + 1];
for (long long int i = 1; i < n + 1; i++) cin >> a[i];
while (m--) {
long long int l, r, x;
cin >> l >> r >> x;
long long int cnt = 0;
for (long long int i = l; i < r + 1; i++)
if (a[i] < a[x]) cnt++;
if (cnt + l == x)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| ### Prompt
Generate a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void init() {}
int main() {
init();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n, m;
cin >> n >> m;
long long int a[n + 1];
for (long long int i = 1; i < n + 1; i++) cin >> a[i];
while (m--) {
long long int l, r, x;
cin >> l >> r >> x;
long long int cnt = 0;
for (long long int i = l; i < r + 1; i++)
if (a[i] < a[x]) cnt++;
if (cnt + l == x)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, a, b, c, x, n, ss[3], m, k, t1, l, r, t2, t3, t4, t5, t6,
y, z, t, tt;
cin >> n >> m;
vector<int> p, tmp, qt;
for (j = 0; j < n; j++) {
cin >> x;
p.push_back(x);
}
for (j = 0; j < m; j++) {
cin >> l >> r >> t6;
t6--;
l--;
r--;
if (t6 < l || t6 > r) {
cout << "Yes" << endl;
continue;
}
if (l == r) {
cout << "Yes" << endl;
continue;
}
tt = 0;
for (k = l; k <= r; k++) {
t2 = p[k];
if (t2 < p[t6]) tt++;
}
tt = tt + l;
if (tt == t6)
cout << "Yes" << endl;
else
cout << "No" << endl;
tmp.clear();
}
}
| ### Prompt
In Cpp, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, a, b, c, x, n, ss[3], m, k, t1, l, r, t2, t3, t4, t5, t6,
y, z, t, tt;
cin >> n >> m;
vector<int> p, tmp, qt;
for (j = 0; j < n; j++) {
cin >> x;
p.push_back(x);
}
for (j = 0; j < m; j++) {
cin >> l >> r >> t6;
t6--;
l--;
r--;
if (t6 < l || t6 > r) {
cout << "Yes" << endl;
continue;
}
if (l == r) {
cout << "Yes" << endl;
continue;
}
tt = 0;
for (k = l; k <= r; k++) {
t2 = p[k];
if (t2 < p[t6]) tt++;
}
tt = tt + l;
if (tt == t6)
cout << "Yes" << endl;
else
cout << "No" << endl;
tmp.clear();
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
void cass() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
};
const int N = 1e5 + 6;
int n, m;
int a[N];
int main() {
cass();
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
int x, y, z;
for (int i = 1; i <= m; i++) {
cin >> x >> y >> z;
int numStrictLess = 0;
for (int i = x; i <= y; i++)
if (a[i] < a[z]) numStrictLess++;
if (numStrictLess != z - x)
cout << "No" << '\n';
else
cout << "Yes" << '\n';
}
}
| ### Prompt
In Cpp, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void cass() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
};
const int N = 1e5 + 6;
int n, m;
int a[N];
int main() {
cass();
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
int x, y, z;
for (int i = 1; i <= m; i++) {
cin >> x >> y >> z;
int numStrictLess = 0;
for (int i = x; i <= y; i++)
if (a[i] < a[z]) numStrictLess++;
if (numStrictLess != z - x)
cout << "No" << '\n';
else
cout << "Yes" << '\n';
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, l, r, x, _, k;
cin >> n >> m;
int orig[n];
for (i = 0; i < n; i++) cin >> orig[i];
for (i = 0; i < m; i++) {
cin >> l >> r >> x;
int temp = orig[x - 1];
k = 0;
for (_ = l - 1; _ < r; _++) {
if (orig[_] < temp) k++;
}
if (l + k == x) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, l, r, x, _, k;
cin >> n >> m;
int orig[n];
for (i = 0; i < n; i++) cin >> orig[i];
for (i = 0; i < m; i++) {
cin >> l >> r >> x;
int temp = orig[x - 1];
k = 0;
for (_ = l - 1; _ < r; _++) {
if (orig[_] < temp) k++;
}
if (l + k == x) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, MOD = 1e9 + 7;
int a[N], b[N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", a + i);
for (int i = 0; i < m; i++) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
int cnt = 0;
for (int j = l - 1; j < r; j++) {
if (a[j] < a[x - 1]) cnt++;
}
if (cnt == x - l)
puts("Yes");
else
puts("No");
}
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, MOD = 1e9 + 7;
int a[N], b[N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", a + i);
for (int i = 0; i < m; i++) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
int cnt = 0;
for (int j = l - 1; j < r; j++) {
if (a[j] < a[x - 1]) cnt++;
}
if (cnt == x - l)
puts("Yes");
else
puts("No");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
bool prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
int m;
cin >> n >> m;
vector<int> v(n);
vector<int> v2(n);
map<int, int> mapa;
for (int i = 0; i < n; i++) {
cin >> v[i];
mapa[i + 1] = v[i];
v2[i] = v[i];
}
for (int i = 0; i < m; i++) {
int l;
int r;
int x;
cin >> l >> r >> x;
int c = 0;
int aux = v[x - 1];
for (int j = l - 1; j < r; j++) {
if (aux > v[j]) {
c++;
}
}
int tot = (r - l);
if (v[l - 1 + c] == v[x - 1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
bool prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
int m;
cin >> n >> m;
vector<int> v(n);
vector<int> v2(n);
map<int, int> mapa;
for (int i = 0; i < n; i++) {
cin >> v[i];
mapa[i + 1] = v[i];
v2[i] = v[i];
}
for (int i = 0; i < m; i++) {
int l;
int r;
int x;
cin >> l >> r >> x;
int c = 0;
int aux = v[x - 1];
for (int j = l - 1; j < r; j++) {
if (aux > v[j]) {
c++;
}
}
int tot = (r - l);
if (v[l - 1 + c] == v[x - 1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long cls = 1000000007;
const int INF = 0x3f3f3f3f;
using namespace std;
int p[101000];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i < n + 1; i++) {
scanf("%d", &p[i]);
}
int l, r, x, d, sum;
while (m--) {
scanf("%d%d%d", &l, &r, &x);
sum = 0;
d = x - l;
for (int i = l; i < r + 1; i++) {
if (p[i] < p[x]) {
sum++;
if (sum > d) break;
}
}
if (d == sum) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long cls = 1000000007;
const int INF = 0x3f3f3f3f;
using namespace std;
int p[101000];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i < n + 1; i++) {
scanf("%d", &p[i]);
}
int l, r, x, d, sum;
while (m--) {
scanf("%d%d%d", &l, &r, &x);
sum = 0;
d = x - l;
for (int i = l; i < r + 1; i++) {
if (p[i] < p[x]) {
sum++;
if (sum > d) break;
}
}
if (d == sum) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[1000001];
int main() {
int n, m, l, r, x, tmp;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int j = 1; j <= m; j++) {
scanf("%d %d %d", &l, &r, &x);
tmp = a[x];
int cnt = 0;
for (int i = l; i <= r; i++) {
if (tmp > a[i]) cnt++;
}
if (a[l + cnt] == tmp)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
Please create a solution in cpp to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1000001];
int main() {
int n, m, l, r, x, tmp;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int j = 1; j <= m; j++) {
scanf("%d %d %d", &l, &r, &x);
tmp = a[x];
int cnt = 0;
for (int i = l; i <= r; i++) {
if (tmp > a[i]) cnt++;
}
if (a[l + cnt] == tmp)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, m, l, r, x, p[10004];
bool hasPositionChanged(int l, int r, int x) {
int lower = 0;
for (int i = l; i <= r; i++) {
lower += p[i] < p[x];
}
return l + lower != x;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
while (m--) {
cin >> l >> r >> x;
cout << (hasPositionChanged(l, r, x) ? "No" : "Yes") << endl;
}
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, l, r, x, p[10004];
bool hasPositionChanged(int l, int r, int x) {
int lower = 0;
for (int i = l; i <= r; i++) {
lower += p[i] < p[x];
}
return l + lower != x;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
while (m--) {
cin >> l >> r >> x;
cout << (hasPositionChanged(l, r, x) ? "No" : "Yes") << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, ans, a[10006], l, r, w;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
ans = 0;
cin >> l >> r >> w;
for (int i = r; i >= l; i--) {
if (a[i] < a[w]) {
ans++;
}
}
if (ans == w - l) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, ans, a[10006], l, r, w;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
ans = 0;
cin >> l >> r >> w;
for (int i = r; i >= l; i--) {
if (a[i] < a[w]) {
ans++;
}
}
if (ans == w - l) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
struct code {
int x, y;
};
bool comp(code a, code b) { return a.x < b.x or (a.x == b.x and a.y < b.y); }
int gcd(int a, int b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
const int MX = 2e5 + 10;
int a[MX], n, m, ok, temp[MX];
int cnt[MX];
map<int, int> mp;
bool check() { return 1; }
int main() {
int n, m, L, R, x;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
temp[i] = a[i];
}
while (m--) {
cin >> L >> R >> x;
int q = a[x];
for (int i = L; i <= R; i++) {
cnt[a[i]]++;
}
for (int i = 1; i <= n; i++) {
if (cnt[i]) a[L++] = i;
cnt[i] = 0;
}
if (a[x] == q)
cout << "Yes\n";
else
cout << "No\n";
for (int i = 1; i <= n; i++) {
a[i] = temp[i];
}
}
}
| ### Prompt
Generate a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct code {
int x, y;
};
bool comp(code a, code b) { return a.x < b.x or (a.x == b.x and a.y < b.y); }
int gcd(int a, int b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
const int MX = 2e5 + 10;
int a[MX], n, m, ok, temp[MX];
int cnt[MX];
map<int, int> mp;
bool check() { return 1; }
int main() {
int n, m, L, R, x;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
temp[i] = a[i];
}
while (m--) {
cin >> L >> R >> x;
int q = a[x];
for (int i = L; i <= R; i++) {
cnt[a[i]]++;
}
for (int i = 1; i <= n; i++) {
if (cnt[i]) a[L++] = i;
cnt[i] = 0;
}
if (a[x] == q)
cout << "Yes\n";
else
cout << "No\n";
for (int i = 1; i <= n; i++) {
a[i] = temp[i];
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[10005];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
int c(0), z = a[x - 1];
for (int j = l - 1; j < r; j++) {
if (z > a[j]) c++;
}
if (c == x - l)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[10005];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
int c(0), z = a[x - 1];
for (int j = l - 1; j < r; j++) {
if (z > a[j]) c++;
}
if (c == x - l)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int p[10005];
int main() {
int i, j, k, l, m, n, x, r;
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> p[i];
}
for (i = 0; i < m; i++) {
cin >> l >> r >> x;
int countt = 0;
l--;
r--;
x--;
for (j = l; j <= r; j++) {
if (p[j] < p[x]) {
countt++;
}
}
if (countt == x - l) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int p[10005];
int main() {
int i, j, k, l, m, n, x, r;
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> p[i];
}
for (i = 0; i < m; i++) {
cin >> l >> r >> x;
int countt = 0;
l--;
r--;
x--;
for (j = l; j <= r; j++) {
if (p[j] < p[x]) {
countt++;
}
}
if (countt == x - l) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 12345;
vector<int> tree[5 * N];
int A[N];
vector<int> merge(vector<int> &L, vector<int> &R) {
int nl = L.size();
int nr = R.size();
int i = 0, j = 0;
vector<int> ret;
while (i < nl && j < nr) {
if (L[i] < R[j]) {
ret.push_back(L[i++]);
} else {
ret.push_back(R[j++]);
}
}
while (i < nl) ret.push_back(L[i++]);
while (j < nr) ret.push_back(R[j++]);
return ret;
}
void build_tree(int cur, int l, int r) {
if (l == r) {
tree[cur].push_back(A[l]);
return;
}
int mid = l + (r - l) / 2;
build_tree(2 * cur + 1, l, mid);
build_tree(2 * cur + 2, mid + 1, r);
tree[cur] = merge(tree[2 * cur + 1], tree[2 * cur + 2]);
}
int query(int curr, int qs, int qe, int ss, int se, int k) {
if (qe < ss || qs > se) return 0;
if (ss >= qs && se <= qe) {
return lower_bound(tree[curr].begin(), tree[curr].end(), k) -
tree[curr].begin();
}
int mid = (ss + se) / 2;
int l = query(2 * curr + 1, qs, qe, ss, mid, k);
int r = query(2 * curr + 2, qs, qe, mid + 1, se, k);
return l + r;
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> A[i];
A[i]--;
}
build_tree(0, 0, n - 1);
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l--, r--, x--;
int idx = query(0, l, r, 0, n - 1, A[x]);
if (x < l || x > r) {
cout << "Yes\n";
continue;
}
int pos = l + idx;
if (pos == x)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 12345;
vector<int> tree[5 * N];
int A[N];
vector<int> merge(vector<int> &L, vector<int> &R) {
int nl = L.size();
int nr = R.size();
int i = 0, j = 0;
vector<int> ret;
while (i < nl && j < nr) {
if (L[i] < R[j]) {
ret.push_back(L[i++]);
} else {
ret.push_back(R[j++]);
}
}
while (i < nl) ret.push_back(L[i++]);
while (j < nr) ret.push_back(R[j++]);
return ret;
}
void build_tree(int cur, int l, int r) {
if (l == r) {
tree[cur].push_back(A[l]);
return;
}
int mid = l + (r - l) / 2;
build_tree(2 * cur + 1, l, mid);
build_tree(2 * cur + 2, mid + 1, r);
tree[cur] = merge(tree[2 * cur + 1], tree[2 * cur + 2]);
}
int query(int curr, int qs, int qe, int ss, int se, int k) {
if (qe < ss || qs > se) return 0;
if (ss >= qs && se <= qe) {
return lower_bound(tree[curr].begin(), tree[curr].end(), k) -
tree[curr].begin();
}
int mid = (ss + se) / 2;
int l = query(2 * curr + 1, qs, qe, ss, mid, k);
int r = query(2 * curr + 2, qs, qe, mid + 1, se, k);
return l + r;
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> A[i];
A[i]--;
}
build_tree(0, 0, n - 1);
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l--, r--, x--;
int idx = query(0, l, r, 0, n - 1, A[x]);
if (x < l || x > r) {
cout << "Yes\n";
continue;
}
int pos = l + idx;
if (pos == x)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
int main(void) {
int n, m, ara[10001] = {0}, l, r, x, i, count;
scanf("%d %d", &n, &m);
for (i = 1; i <= n; i++) {
scanf("%d", &ara[i]);
}
while (m--) {
scanf("%d %d %d", &l, &r, &x);
count = 0;
for (i = l; i <= r; i++) {
if (ara[i] < ara[x]) {
count++;
}
}
if (count == (x - l)) {
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
int main(void) {
int n, m, ara[10001] = {0}, l, r, x, i, count;
scanf("%d %d", &n, &m);
for (i = 1; i <= n; i++) {
scanf("%d", &ara[i]);
}
while (m--) {
scanf("%d %d %d", &l, &r, &x);
count = 0;
for (i = l; i <= r; i++) {
if (ara[i] < ara[x]) {
count++;
}
}
if (count == (x - l)) {
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int l, r, x;
int s;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
s = 0;
for (int k = l - 1; k < r; k++) {
if (v[k] < v[x - 1]) s++;
}
if (s == x - l)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int l, r, x;
int s;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
s = 0;
for (int k = l - 1; k < r; k++) {
if (v[k] < v[x - 1]) s++;
}
if (s == x - l)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10100;
int a[maxn], b[maxn];
int cmp(int x, int y) { return x < y; }
int main() {
int n, m, i;
scanf("%d%d", &n, &m);
for (i = 0; i < n; ++i) scanf("%d", &a[i]);
for (int j = 0; j < m; ++j) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
int l = 0;
int r = 0;
for (i = x - 1; i <= y - 1; ++i)
if (a[i] < a[z - 1])
l++;
else if (a[i] > a[z - 1])
r++;
if (l == (z - x) && r == (y - z))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10100;
int a[maxn], b[maxn];
int cmp(int x, int y) { return x < y; }
int main() {
int n, m, i;
scanf("%d%d", &n, &m);
for (i = 0; i < n; ++i) scanf("%d", &a[i]);
for (int j = 0; j < m; ++j) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
int l = 0;
int r = 0;
for (i = x - 1; i <= y - 1; ++i)
if (a[i] < a[z - 1])
l++;
else if (a[i] > a[z - 1])
r++;
if (l == (z - x) && r == (y - z))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long SIZE = 100000;
const int INF = 0x3f3f3f3f;
const long long ll_INF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acos(-1);
const long long MAXN = numeric_limits<long long>::max();
const long long MAX = 2000000;
void disp(vector<long long> v) {
for (auto u : v) cout << u << " ";
cout << '\n';
}
void solve() {
long long n, m, y{};
cin >> n >> m;
vector<long long> p(n), l(m), r(m), x(m);
for (long long i = 0; i < n; i++) cin >> p[i];
for (long long i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> x[i];
y = 0;
for (long long j = l[i] - 1; j < r[i]; j++) {
if (p[j] < p[x[i] - 1]) y++;
}
if (l[i] + y == x[i])
cout << "Yes\n";
else
cout << "No\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long SIZE = 100000;
const int INF = 0x3f3f3f3f;
const long long ll_INF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acos(-1);
const long long MAXN = numeric_limits<long long>::max();
const long long MAX = 2000000;
void disp(vector<long long> v) {
for (auto u : v) cout << u << " ";
cout << '\n';
}
void solve() {
long long n, m, y{};
cin >> n >> m;
vector<long long> p(n), l(m), r(m), x(m);
for (long long i = 0; i < n; i++) cin >> p[i];
for (long long i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> x[i];
y = 0;
for (long long j = l[i] - 1; j < r[i]; j++) {
if (p[j] < p[x[i] - 1]) y++;
}
if (l[i] + y == x[i])
cout << "Yes\n";
else
cout << "No\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int n, m;
scanf("%d %d", &n, &m);
std::vector<int> a;
for (int i = 0; i < n; i++) {
int q;
scanf("%d", &q);
a.push_back(q);
}
for (int i = 0; i < m; ++i) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
int t = a[x - 1], k = 1, k1 = -1;
for (int j = l - 1; j < r; j++) {
if (a[j] < t) {
k++;
} else if (a[j] == t) {
k1++;
}
}
(l - 1) + k == x || ((l - 1) + k < x && x - ((l - 1) + k) <= k1)
? printf("Yes\n")
: printf("No\n");
}
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int n, m;
scanf("%d %d", &n, &m);
std::vector<int> a;
for (int i = 0; i < n; i++) {
int q;
scanf("%d", &q);
a.push_back(q);
}
for (int i = 0; i < m; ++i) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
int t = a[x - 1], k = 1, k1 = -1;
for (int j = l - 1; j < r; j++) {
if (a[j] < t) {
k++;
} else if (a[j] == t) {
k1++;
}
}
(l - 1) + k == x || ((l - 1) + k < x && x - ((l - 1) + k) <= k1)
? printf("Yes\n")
: printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vlli = vector<long long int>;
using vpii = vector<pair<int, int>>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, l, r, x, y;
cin >> n >> m;
vi p(n), b(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
b[i] = p[i];
}
for (int i = 0; i < m; i++) {
y = 0;
cin >> l >> r >> x;
l--;
r--;
x--;
for (int i = l; i <= r; i++)
if (p[i] < p[x]) y++;
if (y == x - l)
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vlli = vector<long long int>;
using vpii = vector<pair<int, int>>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, l, r, x, y;
cin >> n >> m;
vi p(n), b(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
b[i] = p[i];
}
for (int i = 0; i < m; i++) {
y = 0;
cin >> l >> r >> x;
l--;
r--;
x--;
for (int i = l; i <= r; i++)
if (p[i] < p[x]) y++;
if (y == x - l)
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
int P[10004];
int PP[10004];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i < n + 1; i++) cin >> P[i];
for (int i = 0; i < m; i++) {
PP[i] = P[i];
int l, r, x;
cin >> l >> r >> x;
int count = 0;
for (int j = l; j <= r; j++)
if (P[j] < P[x]) count++;
if (count + l == x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
| ### Prompt
Create a solution in Cpp for the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
int P[10004];
int PP[10004];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i < n + 1; i++) cin >> P[i];
for (int i = 0; i < m; i++) {
PP[i] = P[i];
int l, r, x;
cin >> l >> r >> x;
int count = 0;
for (int j = l; j <= r; j++)
if (P[j] < P[x]) count++;
if (count + l == x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[10010];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int l, r, x, cnt = 0;
for (int i = 1; i <= m; i++) {
scanf("%d%d%d", &l, &r, &x);
cnt = 0;
for (int j = l; j <= r; j++)
if (a[j] < a[x]) cnt++;
if (x - l == cnt)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, a[10010];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int l, r, x, cnt = 0;
for (int i = 1; i <= m; i++) {
scanf("%d%d%d", &l, &r, &x);
cnt = 0;
for (int j = l; j <= r; j++)
if (a[j] < a[x]) cnt++;
if (x - l == cnt)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
vector<long long int> ini;
long long int a;
for (int i = 0; i < n; i++) {
cin >> a;
ini.push_back(a);
}
while (m--) {
long long int l, r, x;
cin >> l >> r >> x;
int c = 0;
for (long long int i = l - 1; i != r; i++) {
if (ini[i] > ini[x - 1]) c++;
}
if (x - l == r - l - c)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
vector<long long int> ini;
long long int a;
for (int i = 0; i < n; i++) {
cin >> a;
ini.push_back(a);
}
while (m--) {
long long int l, r, x;
cin >> l >> r >> x;
int c = 0;
for (long long int i = l - 1; i != r; i++) {
if (ini[i] > ini[x - 1]) c++;
}
if (x - l == r - l - c)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
inline long long int in() {
long long int p = 0;
register char ch = 0;
while (ch < '0' or ch > '9') {
ch = getchar();
}
while (ch >= '0' and ch <= '9') {
p = (p << 1) + (p << 3) + ch - '0';
ch = getchar();
}
return p;
}
int main() {
long long int n, m, a, b, pos, el, co, numi;
scanf("%lld%lld", &n, &m);
long long int ar[n];
for (long long int i = 0; i < n; i++) scanf("%lld", &ar[i]);
while (m--) {
co = 0;
scanf("%lld%lld%lld", &a, &b, &pos);
if (pos < a)
printf("Yes\n");
else if (pos > b)
printf("Yes\n");
else if (pos >= a && pos <= b) {
el = ar[pos - 1];
numi = pos - a;
for (long long int i = a - 1; i < b; i++) {
if (el > ar[i]) co++;
}
if (co == numi)
printf("Yes\n");
else
printf("No\n");
}
}
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
inline long long int in() {
long long int p = 0;
register char ch = 0;
while (ch < '0' or ch > '9') {
ch = getchar();
}
while (ch >= '0' and ch <= '9') {
p = (p << 1) + (p << 3) + ch - '0';
ch = getchar();
}
return p;
}
int main() {
long long int n, m, a, b, pos, el, co, numi;
scanf("%lld%lld", &n, &m);
long long int ar[n];
for (long long int i = 0; i < n; i++) scanf("%lld", &ar[i]);
while (m--) {
co = 0;
scanf("%lld%lld%lld", &a, &b, &pos);
if (pos < a)
printf("Yes\n");
else if (pos > b)
printf("Yes\n");
else if (pos >= a && pos <= b) {
el = ar[pos - 1];
numi = pos - a;
for (long long int i = a - 1; i < b; i++) {
if (el > ar[i]) co++;
}
if (co == numi)
printf("Yes\n");
else
printf("No\n");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int i, j, k;
struct query {
int l, r, x;
};
void sort(int *a, int n) {
int maxi = 0;
for (int l = 0; l < n; ++l) maxi = max(maxi, a[l]);
int freq[maxi + 1];
fill(freq, freq + maxi + 1, 0);
for (int l = 0; l < n; ++l) ++freq[a[l]];
int in = 0;
for (int m = 0; m < maxi + 1; ++m) {
while (freq[m]--) a[in++] = m;
}
}
int main() {
int n, m;
cin >> n >> m;
int a[n];
for (i = 0; i < n; ++i) cin >> a[i];
query mom;
int *tmp;
for (i = 0; i < m; ++i) {
cin >> mom.l >> mom.r >> mom.x;
tmp = new int[mom.r - mom.l + 1];
k = 0;
for (j = mom.l - 1; j < mom.r; ++j) tmp[k++] = a[j];
sort(tmp, (mom.r - mom.l + 1));
if (tmp[mom.x - mom.l] == a[mom.x - 1])
cout << "Yes\n";
else
cout << "No\n";
delete tmp;
}
}
| ### Prompt
Please create a solution in cpp to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int i, j, k;
struct query {
int l, r, x;
};
void sort(int *a, int n) {
int maxi = 0;
for (int l = 0; l < n; ++l) maxi = max(maxi, a[l]);
int freq[maxi + 1];
fill(freq, freq + maxi + 1, 0);
for (int l = 0; l < n; ++l) ++freq[a[l]];
int in = 0;
for (int m = 0; m < maxi + 1; ++m) {
while (freq[m]--) a[in++] = m;
}
}
int main() {
int n, m;
cin >> n >> m;
int a[n];
for (i = 0; i < n; ++i) cin >> a[i];
query mom;
int *tmp;
for (i = 0; i < m; ++i) {
cin >> mom.l >> mom.r >> mom.x;
tmp = new int[mom.r - mom.l + 1];
k = 0;
for (j = mom.l - 1; j < mom.r; ++j) tmp[k++] = a[j];
sort(tmp, (mom.r - mom.l + 1));
if (tmp[mom.x - mom.l] == a[mom.x - 1])
cout << "Yes\n";
else
cout << "No\n";
delete tmp;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, l, r, i, s, a[10179];
int main() {
for (cin >> n >> m, i = 1; i <= n; i++) cin >> a[i];
for (; m--;) {
cin >> l >> r >> x;
for (s = 0, i = l; i <= r; i++) a[i] < a[x] ? s++ : 0;
cout << (s + l == x ? "Yes" : "No") << endl;
}
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, x, l, r, i, s, a[10179];
int main() {
for (cin >> n >> m, i = 1; i <= n; i++) cin >> a[i];
for (; m--;) {
cin >> l >> r >> x;
for (s = 0, i = l; i <= r; i++) a[i] < a[x] ? s++ : 0;
cout << (s + l == x ? "Yes" : "No") << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
std::ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int i, a[n + 1];
for (i = 1; i <= n; i++) {
cin >> a[i];
}
int l, r, x, cnt;
while (m--) {
cin >> l >> r >> x;
cnt = 0;
for (i = l; i <= r; i++) {
if (a[i] < a[x]) cnt++;
}
if (cnt == (x - l))
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(void) {
std::ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int i, a[n + 1];
for (i = 1; i <= n; i++) {
cin >> a[i];
}
int l, r, x, cnt;
while (m--) {
cin >> l >> r >> x;
cnt = 0;
for (i = l; i <= r; i++) {
if (a[i] < a[x]) cnt++;
}
if (cnt == (x - l))
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char c) { return '\'' + string(1, c) + '\''; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) res += ", ";
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
string to_str(const int &n) {
ostringstream stm;
stm << n;
return stm.str();
}
string to_str(const long long &n) {
ostringstream stm;
stm << n;
return stm.str();
}
template <class T>
string tostring(T x, int len = 0) {
stringstream ss;
ss << x;
string r = ss.str();
if (int((r).size()) < len) r = string(len - int((r).size()), '0') + r;
return r;
}
template <class T>
void convert(string x, T &r) {
stringstream ss(x);
ss >> r;
}
long long powmod(long long a, long long b) {
long long res = 1;
a %= 1000000007;
for (; b; b >>= 1) {
if (b & 1) res = res * a % 1000000007;
a = a * a % 1000000007;
}
return res;
}
long long modinv(long long a) { return powmod(a, 1000000007 - 2); }
long long modinv(long long a, long long m) { return powmod(a, m - 2); }
long long nCkMp(long long n, long long k) {
long long numerator = 1, denominator = 1;
for (int i = 0; i < k; i++) numerator = (numerator * (n - i)) % 1000000007;
for (int i = 1; i <= k; i++) denominator = (denominator * i) % 1000000007;
return (numerator * modinv(denominator)) % 1000000007;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
int TT = 1, tt;
clock_t t1;
void solve() {
t1 = clock();
int n, m, a, b, c, d = 0;
(cin >> (n));
(cin >> (m));
vector<int> x(n);
for (auto i = (0); i < (n); i++) (cin >> (x[i]));
for (auto i = (0); i < (m); i++) {
(cin >> (a));
(cin >> (b));
(cin >> (c));
d = 0;
for (auto j = (a - 1); j < (b); j++)
if (x[c - 1] > x[j]) d++;
404;
if (a + d == c)
(cout << ("Yes") << endl);
else
(cout << ("No") << endl);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for (tt = 0; tt < TT; tt++) solve();
return EXIT_SUCCESS;
}
| ### Prompt
Create a solution in CPP for the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char c) { return '\'' + string(1, c) + '\''; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) res += ", ";
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
string to_str(const int &n) {
ostringstream stm;
stm << n;
return stm.str();
}
string to_str(const long long &n) {
ostringstream stm;
stm << n;
return stm.str();
}
template <class T>
string tostring(T x, int len = 0) {
stringstream ss;
ss << x;
string r = ss.str();
if (int((r).size()) < len) r = string(len - int((r).size()), '0') + r;
return r;
}
template <class T>
void convert(string x, T &r) {
stringstream ss(x);
ss >> r;
}
long long powmod(long long a, long long b) {
long long res = 1;
a %= 1000000007;
for (; b; b >>= 1) {
if (b & 1) res = res * a % 1000000007;
a = a * a % 1000000007;
}
return res;
}
long long modinv(long long a) { return powmod(a, 1000000007 - 2); }
long long modinv(long long a, long long m) { return powmod(a, m - 2); }
long long nCkMp(long long n, long long k) {
long long numerator = 1, denominator = 1;
for (int i = 0; i < k; i++) numerator = (numerator * (n - i)) % 1000000007;
for (int i = 1; i <= k; i++) denominator = (denominator * i) % 1000000007;
return (numerator * modinv(denominator)) % 1000000007;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
int TT = 1, tt;
clock_t t1;
void solve() {
t1 = clock();
int n, m, a, b, c, d = 0;
(cin >> (n));
(cin >> (m));
vector<int> x(n);
for (auto i = (0); i < (n); i++) (cin >> (x[i]));
for (auto i = (0); i < (m); i++) {
(cin >> (a));
(cin >> (b));
(cin >> (c));
d = 0;
for (auto j = (a - 1); j < (b); j++)
if (x[c - 1] > x[j]) d++;
404;
if (a + d == c)
(cout << ("Yes") << endl);
else
(cout << ("No") << endl);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for (tt = 0; tt < TT; tt++) solve();
return EXIT_SUCCESS;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
array<int, 10001> arr{};
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
int less = 0;
int val = arr[x];
for (int j = l; j <= r; j++) {
if (arr[j] < val) {
less++;
}
}
if (less == x - l) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
| ### Prompt
Generate a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
array<int, 10001> arr{};
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
for (int i = 0; i < m; i++) {
int l, r, x;
cin >> l >> r >> x;
int less = 0;
int val = arr[x];
for (int j = l; j <= r; j++) {
if (arr[j] < val) {
less++;
}
}
if (less == x - l) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const int INF = (int)1e9;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
long long n, m;
cin >> n >> m;
vector<long long> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
long long x, y, z;
while (m--) {
cin >> x >> y >> z;
long long c1 = 0, c2 = 0;
for (int i = x; i <= z; i++)
if (a[i] > a[z]) c1++;
for (int i = z; i <= y; i++)
if (a[i] < a[z]) c2++;
if (c1 == c2)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const int INF = (int)1e9;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
long long n, m;
cin >> n >> m;
vector<long long> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
long long x, y, z;
while (m--) {
cin >> x >> y >> z;
long long c1 = 0, c2 = 0;
for (int i = x; i <= z; i++)
if (a[i] > a[z]) c1++;
for (int i = z; i <= y; i++)
if (a[i] < a[z]) c2++;
if (c1 == c2)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, l, r, x;
int e[10000 + 10];
cin >> n >> m;
for (int i = 0; i < n; i++) scanf("%d", &e[i]);
for (int i = 0; i < m; i++) {
scanf("%d %d %d", &l, &r, &x);
int c = 0;
int k = x - l;
while (l <= r) {
if (e[l - 1] < e[x - 1]) c++;
l++;
}
if (c == k)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, l, r, x;
int e[10000 + 10];
cin >> n >> m;
for (int i = 0; i < n; i++) scanf("%d", &e[i]);
for (int i = 0; i < m; i++) {
scanf("%d %d %d", &l, &r, &x);
int c = 0;
int k = x - l;
while (l <= r) {
if (e[l - 1] < e[x - 1]) c++;
l++;
}
if (c == k)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int ara[10005];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
scanf("%d", &ara[i]);
}
int l, r, x, val, cnt;
for (int i = 1; i <= m; i++) {
scanf("%d %d %d", &l, &r, &x);
cnt = 0;
val = ara[x];
for (int j = l; j <= r; j++) {
if (ara[j] < val) cnt++;
}
if (cnt + l == x)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int ara[10005];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
scanf("%d", &ara[i]);
}
int l, r, x, val, cnt;
for (int i = 1; i <= m; i++) {
scanf("%d %d %d", &l, &r, &x);
cnt = 0;
val = ara[x];
for (int j = l; j <= r; j++) {
if (ara[j] < val) cnt++;
}
if (cnt + l == x)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int v[20000];
int n;
int solve(int l, int r, int pos) {
bool tem[20000];
memset(tem, 0, sizeof tem);
vector<int> aux;
for (int i = l; i <= r; i++) {
tem[v[i]] = 1;
}
for (int i = 0; i <= n; i++) {
if (tem[i]) aux.push_back(i);
}
cout << endl;
if (aux[pos - l] == v[pos]) {
return true;
} else
return false;
}
int main() {
int m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int l, r, x;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
l--, r--, x--;
if (solve(l, r, x)) {
cout << "Yes\n";
} else
cout << "No\n";
}
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int v[20000];
int n;
int solve(int l, int r, int pos) {
bool tem[20000];
memset(tem, 0, sizeof tem);
vector<int> aux;
for (int i = l; i <= r; i++) {
tem[v[i]] = 1;
}
for (int i = 0; i <= n; i++) {
if (tem[i]) aux.push_back(i);
}
cout << endl;
if (aux[pos - l] == v[pos]) {
return true;
} else
return false;
}
int main() {
int m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int l, r, x;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
l--, r--, x--;
if (solve(l, r, x)) {
cout << "Yes\n";
} else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m;
cin >> n >> m;
vector<long long> p(n);
for (long long(i) = 0; (i) < (n); ++(i)) {
cin >> p[i];
--p[i];
}
for (long long(t) = 0; (t) < (m); ++(t)) {
long long l, r, x;
cin >> l >> r >> x;
--l;
--x;
vector<long long> bits(n, 0);
for (long long i = l; i < r; ++i) bits[p[i]] = 1;
long long curpos = 0;
long long next;
for (long long(i) = 0; (i) < (n); ++(i)) {
if (bits[i]) {
if (curpos == x - l) {
next = i;
break;
} else
++curpos;
}
}
cout << (next == p[x] ? "Yes" : "No") << endl;
}
}
int main() {
ios::sync_with_stdio(false);
solve();
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m;
cin >> n >> m;
vector<long long> p(n);
for (long long(i) = 0; (i) < (n); ++(i)) {
cin >> p[i];
--p[i];
}
for (long long(t) = 0; (t) < (m); ++(t)) {
long long l, r, x;
cin >> l >> r >> x;
--l;
--x;
vector<long long> bits(n, 0);
for (long long i = l; i < r; ++i) bits[p[i]] = 1;
long long curpos = 0;
long long next;
for (long long(i) = 0; (i) < (n); ++(i)) {
if (bits[i]) {
if (curpos == x - l) {
next = i;
break;
} else
++curpos;
}
}
cout << (next == p[x] ? "Yes" : "No") << endl;
}
}
int main() {
ios::sync_with_stdio(false);
solve();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int p[10000];
int n, m, l, r, x;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
int s, c = 0;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
l--;
r--, x--;
for (int i = l; i <= r; i++) {
if (p[i] < p[x]) {
c++;
}
}
if (c == x - l) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
c = 0;
}
return 0;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int p[10000];
int n, m, l, r, x;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
int s, c = 0;
for (int i = 0; i < m; i++) {
cin >> l >> r >> x;
l--;
r--, x--;
for (int i = l; i <= r; i++) {
if (p[i] < p[x]) {
c++;
}
}
if (c == x - l) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
c = 0;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int main() {
int n, m, l, r, x, c = 0;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (; m; m--) {
cin >> l >> r >> x;
l--, r--, x--;
c = 0;
for (int i = l; i <= r; i++)
if (a[i] < a[x]) c++;
if (c == x - l)
puts("Yes");
else
puts("No");
}
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int main() {
int n, m, l, r, x, c = 0;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (; m; m--) {
cin >> l >> r >> x;
l--, r--, x--;
c = 0;
for (int i = l; i <= r; i++)
if (a[i] < a[x]) c++;
if (c == x - l)
puts("Yes");
else
puts("No");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a[10005] = {0}, i, l, r, x, count = 0;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
while (m--) {
scanf("%d%d%d", &l, &r, &x);
l--;
r--;
x--;
count = 0;
for (i = l; i <= r; i++) {
if (a[i] < a[x]) count++;
}
if (count == (x - l))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a[10005] = {0}, i, l, r, x, count = 0;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
while (m--) {
scanf("%d%d%d", &l, &r, &x);
l--;
r--;
x--;
count = 0;
for (i = l; i <= r; i++) {
if (a[i] < a[x]) count++;
}
if (count == (x - l))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, m, i, a[10010], l, x, r, count;
cin >> n >> m;
for (i = 1; i <= n; i++) cin >> a[i];
while (m--) {
cin >> l >> r >> x;
count = x - l;
for (i = l; i <= r; i++)
if (a[i] < a[x]) count--;
if (count == 0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, m, i, a[10010], l, x, r, count;
cin >> n >> m;
for (i = 1; i <= n; i++) cin >> a[i];
while (m--) {
cin >> l >> r >> x;
count = x - l;
for (i = l; i <= r; i++)
if (a[i] < a[x]) count--;
if (count == 0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, l, r, i, s, a[10179];
int main() {
for (cin >> n >> m, i = 1; i <= n; i++) {
cin >> a[i];
}
while (m--) {
cin >> l >> r >> x;
for (s = 0, i = l; i <= r; i++) {
if (a[i] < a[x]) s++;
}
if (s + l != x)
cout << "No\n";
else
cout << "Yes\n";
}
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, x, l, r, i, s, a[10179];
int main() {
for (cin >> n >> m, i = 1; i <= n; i++) {
cin >> a[i];
}
while (m--) {
cin >> l >> r >> x;
for (s = 0, i = l; i <= r; i++) {
if (a[i] < a[x]) s++;
}
if (s + l != x)
cout << "No\n";
else
cout << "Yes\n";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
return a * (b / gcd(a, b));
}
int n, m, p[5000005];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
int ct = 0;
for (int i = l; i <= r; i++) {
if (p[i] < p[x]) ct++;
}
if ((x - l) == ct)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
return a * (b / gcd(a, b));
}
int n, m, p[5000005];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
x--;
int ct = 0;
for (int i = l; i <= r; i++) {
if (p[i] < p[x]) ct++;
}
if ((x - l) == ct)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int min(long long int a, long long int b) {
if (a < b)
return a;
else
return b;
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int lo, hi, x;
int cg, cl;
while (m--) {
scanf("%d%d%d", &lo, &hi, &x);
cg = cl = 0;
for (int i = lo; i <= hi; i++) {
if (a[i] > a[x])
cg++;
else if (a[i] < a[x])
cl++;
}
if (x - lo == cl && hi - x == cg)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input
First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.
Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.
Output
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Examples
Input
5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3
Output
Yes
No
Yes
Yes
No
Input
6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3
Output
Yes
No
Yes
No
Yes
Note
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int min(long long int a, long long int b) {
if (a < b)
return a;
else
return b;
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int lo, hi, x;
int cg, cl;
while (m--) {
scanf("%d%d%d", &lo, &hi, &x);
cg = cl = 0;
for (int i = lo; i <= hi; i++) {
if (a[i] > a[x])
cg++;
else if (a[i] < a[x])
cl++;
}
if (x - lo == cl && hi - x == cg)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
const long long MAX = INT_MAX;
const long long inf = 1e18 + 5;
const double pi = 3.14159265358979323846;
long long dirX[] = {1, -1, 0, 0};
long long dirY[] = {0, 0, 1, -1};
using namespace std;
int32_t main() {
long long n;
cin >> n;
long long k;
cin >> k;
long long A[n];
long long pow2[n];
long long pow5[n];
long long sum = 0;
for (long long i = 0; i < n; i++) {
cin >> A[i];
long long count = 0;
long long temp = A[i];
while (temp % 2 == 0) {
temp /= 2;
count++;
}
pow2[i] = count;
temp = A[i];
count = 0;
while (temp % 5 == 0) {
temp /= 5;
count++;
}
pow5[i] = count;
sum += count;
}
long long dp[k + 1][sum + 1];
for (long long j = 0; j <= k; j++)
for (long long ki = 0; ki <= sum; ki++) dp[j][ki] = -1;
dp[0][0] = 0;
for (long long i = 0; i < n; i++) {
for (long long j = k - 1; j >= 0; j--) {
for (long long ki = 0; ki <= sum; ki++) {
if (dp[j][ki] >= 0) {
dp[j + 1][ki + pow5[i]] =
max(dp[j][ki] + pow2[i], dp[j + 1][ki + pow5[i]]);
}
}
}
}
long long ans = 0;
for (long long i = 0; i <= sum; i++) {
ans = max(ans, min(i, dp[k][i]));
}
cout << ans << "\n";
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
const long long MAX = INT_MAX;
const long long inf = 1e18 + 5;
const double pi = 3.14159265358979323846;
long long dirX[] = {1, -1, 0, 0};
long long dirY[] = {0, 0, 1, -1};
using namespace std;
int32_t main() {
long long n;
cin >> n;
long long k;
cin >> k;
long long A[n];
long long pow2[n];
long long pow5[n];
long long sum = 0;
for (long long i = 0; i < n; i++) {
cin >> A[i];
long long count = 0;
long long temp = A[i];
while (temp % 2 == 0) {
temp /= 2;
count++;
}
pow2[i] = count;
temp = A[i];
count = 0;
while (temp % 5 == 0) {
temp /= 5;
count++;
}
pow5[i] = count;
sum += count;
}
long long dp[k + 1][sum + 1];
for (long long j = 0; j <= k; j++)
for (long long ki = 0; ki <= sum; ki++) dp[j][ki] = -1;
dp[0][0] = 0;
for (long long i = 0; i < n; i++) {
for (long long j = k - 1; j >= 0; j--) {
for (long long ki = 0; ki <= sum; ki++) {
if (dp[j][ki] >= 0) {
dp[j + 1][ki + pow5[i]] =
max(dp[j][ki] + pow2[i], dp[j + 1][ki + pow5[i]]);
}
}
}
}
long long ans = 0;
for (long long i = 0; i <= sum; i++) {
ans = max(ans, min(i, dp[k][i]));
}
cout << ans << "\n";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool Check(int val, int pos) { return bool(val & (1 << pos)); }
int Set(int val, int pos) { return val | (1 << pos); }
int Reset(int val, int pos) { return val & (~(1 << pos)); }
int Flip(int val, int pos) { return val ^ (1 << pos); }
long long t, caseno, n, k;
long long Pre(long long val, long long id) {
long long tot = 0;
while (val % id == 0) {
val /= id;
tot++;
}
return tot;
}
struct info {
long long x, y;
} a[202];
long long dp[202][5003];
long long dp1[202][5003];
long long visit[202][5003];
int main() {
long long i, j, f, ff;
scanf("%lld%lld", &n, &k);
long long tot = 0;
for (i = 1; i <= n; i++) {
long long x;
scanf("%lld", &x);
if (i == 1) ff = x;
a[i].x = Pre(x, 2);
a[i].y = Pre(x, 5);
tot += a[i].y;
}
memset(dp, -1, sizeof dp);
dp[0][0] = 0;
long long res = 0;
for (i = 1; i <= n; i++) {
memset(visit, 0, sizeof visit);
for (j = 1; j <= k; j++) {
for (f = 0; f <= tot; f++) {
if (a[i].y <= f && dp[j - 1][f - a[i].y] != -1) {
dp1[j][f] = max(dp[j][f], a[i].x + dp[j - 1][f - a[i].y]);
visit[j][f] = 1;
}
}
}
for (j = 1; j <= k; j++) {
for (f = 0; f <= tot; f++) {
if (visit[j][f]) {
dp[j][f] = dp1[j][f];
}
}
}
}
for (i = 1; i <= k; i++) {
for (j = 0; j <= tot; j++) {
if (dp[i][j] != -1) res = max(res, min(dp[i][j], j));
}
}
printf("%lld\n", res);
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool Check(int val, int pos) { return bool(val & (1 << pos)); }
int Set(int val, int pos) { return val | (1 << pos); }
int Reset(int val, int pos) { return val & (~(1 << pos)); }
int Flip(int val, int pos) { return val ^ (1 << pos); }
long long t, caseno, n, k;
long long Pre(long long val, long long id) {
long long tot = 0;
while (val % id == 0) {
val /= id;
tot++;
}
return tot;
}
struct info {
long long x, y;
} a[202];
long long dp[202][5003];
long long dp1[202][5003];
long long visit[202][5003];
int main() {
long long i, j, f, ff;
scanf("%lld%lld", &n, &k);
long long tot = 0;
for (i = 1; i <= n; i++) {
long long x;
scanf("%lld", &x);
if (i == 1) ff = x;
a[i].x = Pre(x, 2);
a[i].y = Pre(x, 5);
tot += a[i].y;
}
memset(dp, -1, sizeof dp);
dp[0][0] = 0;
long long res = 0;
for (i = 1; i <= n; i++) {
memset(visit, 0, sizeof visit);
for (j = 1; j <= k; j++) {
for (f = 0; f <= tot; f++) {
if (a[i].y <= f && dp[j - 1][f - a[i].y] != -1) {
dp1[j][f] = max(dp[j][f], a[i].x + dp[j - 1][f - a[i].y]);
visit[j][f] = 1;
}
}
}
for (j = 1; j <= k; j++) {
for (f = 0; f <= tot; f++) {
if (visit[j][f]) {
dp[j][f] = dp1[j][f];
}
}
}
}
for (i = 1; i <= k; i++) {
for (j = 0; j <= tot; j++) {
if (dp[i][j] != -1) res = max(res, min(dp[i][j], j));
}
}
printf("%lld\n", res);
return 0;
}
``` |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,no-stack-protector")
using namespace std;
function<void(void)> ____ = []() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
};
template <typename T>
void operator<<(vector<T> &__container, T x) {
__container.push_back(x);
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> &__container) {
for (T _ : __container) out << _ << ' ';
return out;
}
const int MAXN = 2e5 + 7;
int f[2][205][6007];
void solve() {
int n, k;
scanf("%d", &n);
scanf("%d", &k);
vector<pair<int, int> > A(n, {0, 0});
for (int i = 0; i < n; i++) {
long long int x;
scanf("%I64d", &x);
while (x % 2 == 0) x >>= 1, A[i].first++;
while (x % 5 == 0) x /= 5, A[i].second++;
}
int tag = 0;
memset(f, 255, sizeof(f));
f[0][0][0] = 0;
for (int i = 1; i <= n; i++) {
tag ^= 1;
memcpy(f[tag], f[tag ^ 1], sizeof f[tag]);
for (int j = 0; j <= min(i - 1, k - 1); j++) {
for (int cnt_5 = 0; cnt_5 <= 6000; cnt_5++) {
if (f[tag ^ 1][j][cnt_5] == -1) continue;
((f[tag][j + 1][cnt_5 + A[i - 1].second]) =
(f[tag][j + 1][cnt_5 + A[i - 1].second]) >
(f[tag ^ 1][j][cnt_5] + A[i - 1].first)
? (f[tag][j + 1][cnt_5 + A[i - 1].second])
: (f[tag ^ 1][j][cnt_5] + A[i - 1].first));
}
}
}
int ret = 0;
for (int i = 1; i <= k; i++)
for (int j = 0; j <= 6000; j++)
if (f[tag][i][j] != -1)
((ret) =
(ret) > (min(f[tag][i][j], j)) ? (ret) : (min(f[tag][i][j], j)));
cout << ret << "\n";
}
int main() {
solve();
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,no-stack-protector")
using namespace std;
function<void(void)> ____ = []() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
};
template <typename T>
void operator<<(vector<T> &__container, T x) {
__container.push_back(x);
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> &__container) {
for (T _ : __container) out << _ << ' ';
return out;
}
const int MAXN = 2e5 + 7;
int f[2][205][6007];
void solve() {
int n, k;
scanf("%d", &n);
scanf("%d", &k);
vector<pair<int, int> > A(n, {0, 0});
for (int i = 0; i < n; i++) {
long long int x;
scanf("%I64d", &x);
while (x % 2 == 0) x >>= 1, A[i].first++;
while (x % 5 == 0) x /= 5, A[i].second++;
}
int tag = 0;
memset(f, 255, sizeof(f));
f[0][0][0] = 0;
for (int i = 1; i <= n; i++) {
tag ^= 1;
memcpy(f[tag], f[tag ^ 1], sizeof f[tag]);
for (int j = 0; j <= min(i - 1, k - 1); j++) {
for (int cnt_5 = 0; cnt_5 <= 6000; cnt_5++) {
if (f[tag ^ 1][j][cnt_5] == -1) continue;
((f[tag][j + 1][cnt_5 + A[i - 1].second]) =
(f[tag][j + 1][cnt_5 + A[i - 1].second]) >
(f[tag ^ 1][j][cnt_5] + A[i - 1].first)
? (f[tag][j + 1][cnt_5 + A[i - 1].second])
: (f[tag ^ 1][j][cnt_5] + A[i - 1].first));
}
}
}
int ret = 0;
for (int i = 1; i <= k; i++)
for (int j = 0; j <= 6000; j++)
if (f[tag][i][j] != -1)
((ret) =
(ret) > (min(f[tag][i][j], j)) ? (ret) : (min(f[tag][i][j], j)));
cout << ret << "\n";
}
int main() {
solve();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int dp[5250][210];
long long tv[250], fv[250];
int main() {
for (int i = 0; i < 5250; i++)
for (int j = 0; j < 210; j++) {
dp[i][j] = -999999;
}
dp[0][0] = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
long long t;
cin >> t;
int c2 = 0, c5 = 0;
while (!(t % 2)) {
t /= 2;
c2++;
}
while (!(t % 5)) {
t /= 5;
c5++;
}
tv[i] = c2;
fv[i] = c5;
}
for (int i = 0; i < n; i++) {
int it = min(k, i + 1);
for (int j = it - 1; j >= 0; j--) {
for (int l = 0; l < 26 * (i + 1); l++) {
dp[l + fv[i]][j + 1] = max(dp[l + fv[i]][j + 1], dp[l][j] + (int)tv[i]);
}
}
}
int mp = 0;
for (int i = 0; i < 5250; i++) {
mp = max(mp, min(dp[i][k], i));
}
cout << mp << '\n';
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
int dp[5250][210];
long long tv[250], fv[250];
int main() {
for (int i = 0; i < 5250; i++)
for (int j = 0; j < 210; j++) {
dp[i][j] = -999999;
}
dp[0][0] = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
long long t;
cin >> t;
int c2 = 0, c5 = 0;
while (!(t % 2)) {
t /= 2;
c2++;
}
while (!(t % 5)) {
t /= 5;
c5++;
}
tv[i] = c2;
fv[i] = c5;
}
for (int i = 0; i < n; i++) {
int it = min(k, i + 1);
for (int j = it - 1; j >= 0; j--) {
for (int l = 0; l < 26 * (i + 1); l++) {
dp[l + fv[i]][j + 1] = max(dp[l + fv[i]][j + 1], dp[l][j] + (int)tv[i]);
}
}
}
int mp = 0;
for (int i = 0; i < 5250; i++) {
mp = max(mp, min(dp[i][k], i));
}
cout << mp << '\n';
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long MX = 26 * 205, INF = 1e6;
long long dp[205][MX];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n = 0, k = 0;
cin >> n >> k;
vector<pair<long long, long long> > ft;
long long a = 0;
for (long long i = 0; i < n; i++) {
cin >> a;
long long curt = 0, curf = 0;
for (long long j = 2; j <= 5; j++) {
while (a % j == 0) {
a /= j;
curt += (j == 2);
curf += (j == 5);
}
}
ft.push_back(make_pair(curt, curf));
}
for (long long i = 0; i <= k; i++)
for (long long j = 1; j < MX; j++) dp[i][j] = -INF;
for (long long i = 0; i < n; i++) {
long long x = ft[i].second, y = ft[i].first;
for (long long j = min(k - 1, i); j >= 0; j--)
for (long long l = 0; l + x < MX; l++)
dp[j + 1][l + x] = max(dp[j + 1][l + x], dp[j][l] + y);
}
long long ans = 0;
for (long long i = 0; i < MX; i++) ans = max(ans, min(dp[k][i], i));
cout << ans;
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MX = 26 * 205, INF = 1e6;
long long dp[205][MX];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n = 0, k = 0;
cin >> n >> k;
vector<pair<long long, long long> > ft;
long long a = 0;
for (long long i = 0; i < n; i++) {
cin >> a;
long long curt = 0, curf = 0;
for (long long j = 2; j <= 5; j++) {
while (a % j == 0) {
a /= j;
curt += (j == 2);
curf += (j == 5);
}
}
ft.push_back(make_pair(curt, curf));
}
for (long long i = 0; i <= k; i++)
for (long long j = 1; j < MX; j++) dp[i][j] = -INF;
for (long long i = 0; i < n; i++) {
long long x = ft[i].second, y = ft[i].first;
for (long long j = min(k - 1, i); j >= 0; j--)
for (long long l = 0; l + x < MX; l++)
dp[j + 1][l + x] = max(dp[j + 1][l + x], dp[j][l] + y);
}
long long ans = 0;
for (long long i = 0; i < MX; i++) ans = max(ans, min(dp[k][i], i));
cout << ans;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 102;
const long long MOD = 1000000007;
int N, K, a[202], b[202], F[202][5002], Res;
int main() {
cin >> N >> K;
memset(F, -1, sizeof(F));
for (int i = 1; i <= N; i++) {
long long tmp, x;
cin >> x;
tmp = x;
while (tmp % 2 == 0 && tmp) a[i]++, tmp /= 2;
tmp = x;
while (tmp % 5 == 0 && tmp) b[i]++, tmp /= 5;
}
F[0][0] = 0;
for (int i = 1; i <= N; i++) {
for (int k = K; k >= 1; k--) {
for (int j = 0; j <= 5000; j++)
if (j >= b[i] && F[k - 1][j - b[i]] != -1) {
F[k][j] = max(F[k][j], F[k - 1][j - b[i]] + a[i]);
}
}
}
for (int j = 1; j <= 5000; j++) Res = max(Res, min(j, F[K][j]));
cout << Res;
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 102;
const long long MOD = 1000000007;
int N, K, a[202], b[202], F[202][5002], Res;
int main() {
cin >> N >> K;
memset(F, -1, sizeof(F));
for (int i = 1; i <= N; i++) {
long long tmp, x;
cin >> x;
tmp = x;
while (tmp % 2 == 0 && tmp) a[i]++, tmp /= 2;
tmp = x;
while (tmp % 5 == 0 && tmp) b[i]++, tmp /= 5;
}
F[0][0] = 0;
for (int i = 1; i <= N; i++) {
for (int k = K; k >= 1; k--) {
for (int j = 0; j <= 5000; j++)
if (j >= b[i] && F[k - 1][j - b[i]] != -1) {
F[k][j] = max(F[k][j], F[k - 1][j - b[i]] + a[i]);
}
}
}
for (int j = 1; j <= 5000; j++) Res = max(Res, min(j, F[K][j]));
cout << Res;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int readint() {
char c;
while (c = getchar(), (c < '0' || c > '9') && c != '-')
;
bool flag = (c == '-');
if (flag) c = getchar();
int x = 0;
while (c >= '0' && c <= '9') {
x = x * 10 + c - 48;
c = getchar();
}
return flag ? -x : x;
}
inline string tos(int x) {
string s;
while (x) s = (char)(x % 10 + '0') + s, x /= 10;
return s;
}
int dp[2][205][5005];
long long a[205], n, k;
int main() {
ios_base::sync_with_stdio(false);
int i, j, l, cnt5, cnt2, ans = 0;
cin >> n >> k;
for (i = 1; i <= n; i++) cin >> a[i];
memset(dp, -1, sizeof(dp));
dp[0][0][0] = 0;
for (i = 1; i <= n; i++) {
cnt2 = cnt5 = 0;
while (a[i] % 2 == 0) cnt2++, a[i] /= 2;
while (a[i] % 5 == 0) cnt5++, a[i] /= 5;
for (j = 0; j <= k; j++)
for (l = 0; l <= 5000; l++) {
dp[i & 1][j][l] = dp[(i - 1) & 1][j][l];
if (j && l >= cnt5 && ~dp[(i - 1) & 1][j - 1][l - cnt5]) {
dp[i & 1][j][l] =
max(dp[i & 1][j][l], dp[(i - 1) & 1][j - 1][l - cnt5] + cnt2);
}
}
}
for (i = 0; i <= 5000; i++) {
ans = max(ans, min(i, dp[n & 1][k][i]));
}
cout << ans << endl;
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int readint() {
char c;
while (c = getchar(), (c < '0' || c > '9') && c != '-')
;
bool flag = (c == '-');
if (flag) c = getchar();
int x = 0;
while (c >= '0' && c <= '9') {
x = x * 10 + c - 48;
c = getchar();
}
return flag ? -x : x;
}
inline string tos(int x) {
string s;
while (x) s = (char)(x % 10 + '0') + s, x /= 10;
return s;
}
int dp[2][205][5005];
long long a[205], n, k;
int main() {
ios_base::sync_with_stdio(false);
int i, j, l, cnt5, cnt2, ans = 0;
cin >> n >> k;
for (i = 1; i <= n; i++) cin >> a[i];
memset(dp, -1, sizeof(dp));
dp[0][0][0] = 0;
for (i = 1; i <= n; i++) {
cnt2 = cnt5 = 0;
while (a[i] % 2 == 0) cnt2++, a[i] /= 2;
while (a[i] % 5 == 0) cnt5++, a[i] /= 5;
for (j = 0; j <= k; j++)
for (l = 0; l <= 5000; l++) {
dp[i & 1][j][l] = dp[(i - 1) & 1][j][l];
if (j && l >= cnt5 && ~dp[(i - 1) & 1][j - 1][l - cnt5]) {
dp[i & 1][j][l] =
max(dp[i & 1][j][l], dp[(i - 1) & 1][j - 1][l - cnt5] + cnt2);
}
}
}
for (i = 0; i <= 5000; i++) {
ans = max(ans, min(i, dp[n & 1][k][i]));
}
cout << ans << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MAX = 6000;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
ll x;
cin >> x;
while (x % 2 == 0) ++a[i], x /= 2;
while (x % 5 == 0) ++b[i], x /= 5;
}
vector<vector<int>> dp(k + 1, vector<int>(MAX + 1, -INF));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = k - 1; j >= 0; j--) {
for (int l = 0; l + b[i] <= MAX; l++) {
dp[j + 1][l + b[i]] = max(dp[j + 1][l + b[i]], dp[j][l] + a[i]);
}
}
}
int res = 0;
for (int i = 0; i <= MAX; i++) {
res = max(res, min(i, dp[k][i]));
}
cout << res << endl;
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MAX = 6000;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
ll x;
cin >> x;
while (x % 2 == 0) ++a[i], x /= 2;
while (x % 5 == 0) ++b[i], x /= 5;
}
vector<vector<int>> dp(k + 1, vector<int>(MAX + 1, -INF));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = k - 1; j >= 0; j--) {
for (int l = 0; l + b[i] <= MAX; l++) {
dp[j + 1][l + b[i]] = max(dp[j + 1][l + b[i]], dp[j][l] + a[i]);
}
}
}
int res = 0;
for (int i = 0; i <= MAX; i++) {
res = max(res, min(i, dp[k][i]));
}
cout << res << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 204;
int n, k;
int dp[2][N][8000], p2[N], p5[N];
long long a;
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%I64d", &a);
while (a % 2 == 0) {
a >>= 1;
p2[i]++;
}
while (a % 5 == 0) {
a /= 5;
p5[i]++;
}
}
memset(dp, -1, sizeof(dp));
dp[0][0][0] = 0;
dp[0][1][p5[0]] = p2[0];
for (int i = 1; i < n; i++) {
for (int j = 0; j <= i + 1; j++) {
for (int l = 0; l < 8000; l++) {
dp[i % 2][j][l] = dp[(i - 1) % 2][j][l];
if (l >= p5[i] and j and dp[(i - 1) % 2][j - 1][l - p5[i]] != -1)
dp[i % 2][j][l] =
max(dp[i % 2][j][l], dp[(i - 1) % 2][j - 1][l - p5[i]] + p2[i]);
}
}
}
int ans = 0;
for (int i = 0; i < 8000; i++) {
ans = max(ans, min(i, dp[(n - 1) % 2][k][i]));
}
printf("%d\n", ans);
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 204;
int n, k;
int dp[2][N][8000], p2[N], p5[N];
long long a;
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%I64d", &a);
while (a % 2 == 0) {
a >>= 1;
p2[i]++;
}
while (a % 5 == 0) {
a /= 5;
p5[i]++;
}
}
memset(dp, -1, sizeof(dp));
dp[0][0][0] = 0;
dp[0][1][p5[0]] = p2[0];
for (int i = 1; i < n; i++) {
for (int j = 0; j <= i + 1; j++) {
for (int l = 0; l < 8000; l++) {
dp[i % 2][j][l] = dp[(i - 1) % 2][j][l];
if (l >= p5[i] and j and dp[(i - 1) % 2][j - 1][l - p5[i]] != -1)
dp[i % 2][j][l] =
max(dp[i % 2][j][l], dp[(i - 1) % 2][j - 1][l - p5[i]] + p2[i]);
}
}
}
int ans = 0;
for (int i = 0; i < 8000; i++) {
ans = max(ans, min(i, dp[(n - 1) % 2][k][i]));
}
printf("%d\n", ans);
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[205], b[205], n, k, ans, dp[205][205 * 40 + 33];
int main(void) {
long long x;
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%lld", &x);
int u = 0, v = 0;
while (x % 5 == 0) u++, x /= 5;
while (x % 2 == 0) v++, x /= 2;
for (int t = k - 1; t >= 0; t--)
for (int j = n * 40; j >= 0; j--)
if (dp[t][j] != -1)
dp[t + 1][j + u] = max(dp[t + 1][j + u], dp[t][j] + v);
}
for (int i = 0; i <= n * 40; i++) ans = max(ans, min(dp[k][i], i));
printf("%d\n", ans);
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[205], b[205], n, k, ans, dp[205][205 * 40 + 33];
int main(void) {
long long x;
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%lld", &x);
int u = 0, v = 0;
while (x % 5 == 0) u++, x /= 5;
while (x % 2 == 0) v++, x /= 2;
for (int t = k - 1; t >= 0; t--)
for (int j = n * 40; j >= 0; j--)
if (dp[t][j] != -1)
dp[t + 1][j + u] = max(dp[t + 1][j + u], dp[t][j] + v);
}
for (int i = 0; i <= n * 40; i++) ans = max(ans, min(dp[k][i], i));
printf("%d\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long dp[500][6010];
long long a[234];
signed main() {
for (long long i = 0; i <= 254; i++) {
for (long long j = 0; j <= 6000; j++) {
dp[i][j] = -1;
}
}
dp[0][0] = 0;
long long n, k;
scanf("%I64d %I64d", &n, &k);
for (long long i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
}
for (long long s = 0; s < n; s++) {
long long g = a[s];
long long t = 0, f = 0;
while (g % 2 == 0) g /= 2, t++;
g = a[s];
while (g % 5 == 0) g /= 5, f++;
for (long long i = k - 1; i >= 0; i--) {
for (long long j = 0; j <= 6000; j++) {
if (dp[i][j] != -1)
dp[i + 1][j + f] = max(dp[i + 1][j + f], dp[i][j] + t);
}
}
}
long long Max = 0;
for (long long i = 0; i <= 6000; i++) {
Max = max(Max, min(i, dp[k][i]));
}
cout << Max << endl;
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long dp[500][6010];
long long a[234];
signed main() {
for (long long i = 0; i <= 254; i++) {
for (long long j = 0; j <= 6000; j++) {
dp[i][j] = -1;
}
}
dp[0][0] = 0;
long long n, k;
scanf("%I64d %I64d", &n, &k);
for (long long i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
}
for (long long s = 0; s < n; s++) {
long long g = a[s];
long long t = 0, f = 0;
while (g % 2 == 0) g /= 2, t++;
g = a[s];
while (g % 5 == 0) g /= 5, f++;
for (long long i = k - 1; i >= 0; i--) {
for (long long j = 0; j <= 6000; j++) {
if (dp[i][j] != -1)
dp[i + 1][j + f] = max(dp[i + 1][j + f], dp[i][j] + t);
}
}
}
long long Max = 0;
for (long long i = 0; i <= 6000; i++) {
Max = max(Max, min(i, dp[k][i]));
}
cout << Max << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng((long long)new char);
const double eps = 1e-8;
const int maxn = 200010;
const long double INF = 1e15;
const int mod = 1e9 + 7;
int dp[210][6010];
int c5[210], c2[210];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, k;
cin >> n >> k;
for (int t = (1); t < (n + 1); ++t) {
long long x;
cin >> x;
long long tx = x;
c2[t] = 0;
while (tx % 2 == 0) tx /= 2, ++c2[t];
tx = x;
c5[t] = 0;
while (tx % 5 == 0) tx /= 5, ++c5[t];
}
memset(dp, 0xcf, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = k; j; --j) {
for (int l = c5[i]; l < 6010; ++l) {
dp[j][l] = max(dp[j][l], dp[j - 1][l - c5[i]] + c2[i]);
}
}
}
int ans = 0;
for (int t = (0); t < (6010); ++t) ans = max(ans, min(t, dp[k][t]));
cout << ans;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng((long long)new char);
const double eps = 1e-8;
const int maxn = 200010;
const long double INF = 1e15;
const int mod = 1e9 + 7;
int dp[210][6010];
int c5[210], c2[210];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, k;
cin >> n >> k;
for (int t = (1); t < (n + 1); ++t) {
long long x;
cin >> x;
long long tx = x;
c2[t] = 0;
while (tx % 2 == 0) tx /= 2, ++c2[t];
tx = x;
c5[t] = 0;
while (tx % 5 == 0) tx /= 5, ++c5[t];
}
memset(dp, 0xcf, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = k; j; --j) {
for (int l = c5[i]; l < 6010; ++l) {
dp[j][l] = max(dp[j][l], dp[j - 1][l - c5[i]] + c2[i]);
}
}
}
int ans = 0;
for (int t = (0); t < (6010); ++t) ans = max(ans, min(t, dp[k][t]));
cout << ans;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long a[205];
int dp[205][22100];
int c2(long long x) {
int ans = 0;
while (x % 2 == 0) {
ans++;
x /= 2;
}
return ans;
}
int c5(long long x) {
int ans = 0;
while (x % 5 == 0) {
ans++;
x /= 5;
}
return ans;
}
int main() {
scanf("%d%d", &n, &k);
int big = 0;
for (int i = 1; i <= n; i++) {
scanf("%I64d", &a[i]);
big += c2(a[i]);
}
int x2, x5;
for (int i = 0; i <= big; i++)
for (int j = 0; j <= k; j++) dp[j][i] = -1;
for (int i = 1; i <= n; i++) {
x2 = c2(a[i]), x5 = c5(a[i]);
for (int j = min(i, k); j >= 2; j--) {
for (int l = 0; l <= big; l++) {
if (l < x2) continue;
if (dp[j - 1][l - x2] == -1) continue;
dp[j][l] = max(dp[j][l], dp[j - 1][l - x2] + x5);
}
}
dp[1][x2] = max(dp[1][x2], x5);
}
int ans = 0, t;
for (int i = 0; i <= big; i++) {
t = min(dp[k][i], i);
ans = max(ans, t);
}
printf("%d\n", ans);
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long a[205];
int dp[205][22100];
int c2(long long x) {
int ans = 0;
while (x % 2 == 0) {
ans++;
x /= 2;
}
return ans;
}
int c5(long long x) {
int ans = 0;
while (x % 5 == 0) {
ans++;
x /= 5;
}
return ans;
}
int main() {
scanf("%d%d", &n, &k);
int big = 0;
for (int i = 1; i <= n; i++) {
scanf("%I64d", &a[i]);
big += c2(a[i]);
}
int x2, x5;
for (int i = 0; i <= big; i++)
for (int j = 0; j <= k; j++) dp[j][i] = -1;
for (int i = 1; i <= n; i++) {
x2 = c2(a[i]), x5 = c5(a[i]);
for (int j = min(i, k); j >= 2; j--) {
for (int l = 0; l <= big; l++) {
if (l < x2) continue;
if (dp[j - 1][l - x2] == -1) continue;
dp[j][l] = max(dp[j][l], dp[j - 1][l - x2] + x5);
}
}
dp[1][x2] = max(dp[1][x2], x5);
}
int ans = 0, t;
for (int i = 0; i <= big; i++) {
t = min(dp[k][i], i);
ans = max(ans, t);
}
printf("%d\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const long long INF = -9999999999999;
const int maxn = 1000006;
const int maxm = 1000006;
const int ox3f = 1061109567;
const int fox3f = -2139062144;
const long long ox3fll = 4557430888798830399;
int n, m, T;
int dp[202][5200];
long long c[202];
int a[202], b[202];
void solve() {
cin >> n >> m;
int sum1 = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
cin >> c[i];
while (c[i] > 0 && c[i] % 2 == 0) {
a[i]++;
c[i] >>= 1;
}
while (c[i] > 0 && c[i] % 5 == 0) {
b[i]++;
c[i] /= 5;
}
sum1 += b[i];
for (int j = sum1; j >= b[i]; j--) {
for (int k = m; k >= 1; k--)
if (dp[k - 1][j - b[i]] != 0)
dp[k][j] = max(dp[k][j], dp[k - 1][j - b[i]] + a[i]);
}
}
int ans = 0;
for (int i = 0; i <= sum1; i++) {
ans = max(ans, min(i, dp[m][i] - 1));
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
solve();
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const long long INF = -9999999999999;
const int maxn = 1000006;
const int maxm = 1000006;
const int ox3f = 1061109567;
const int fox3f = -2139062144;
const long long ox3fll = 4557430888798830399;
int n, m, T;
int dp[202][5200];
long long c[202];
int a[202], b[202];
void solve() {
cin >> n >> m;
int sum1 = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
cin >> c[i];
while (c[i] > 0 && c[i] % 2 == 0) {
a[i]++;
c[i] >>= 1;
}
while (c[i] > 0 && c[i] % 5 == 0) {
b[i]++;
c[i] /= 5;
}
sum1 += b[i];
for (int j = sum1; j >= b[i]; j--) {
for (int k = m; k >= 1; k--)
if (dp[k - 1][j - b[i]] != 0)
dp[k][j] = max(dp[k][j], dp[k - 1][j - b[i]] + a[i]);
}
}
int ans = 0;
for (int i = 0; i <= sum1; i++) {
ans = max(ans, min(i, dp[m][i] - 1));
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
solve();
return 0;
}
``` |
#include <bits/stdc++.h>
int Tss[210], Fss[210], Exs[210];
long long Arr[210];
int N, K;
int DPF[210][5300 * 2 + 10], DPB[210][5300 * 2 + 10];
int Max;
void DPA() {
int wi;
int wic, win;
int cs, ex;
memset(DPF, -0x3F, sizeof(DPF));
memset(DPB, -0x3F, sizeof(DPB));
DPF[0][5300] = DPB[0][5300] = 0;
for (wi = 1; wi <= N; ++wi) {
for (wic = 0; wic <= (K > wi ? wi : K); ++wic)
for (win = 0; win <= 5300 * 2; ++win)
if (DPF[wic][win] >= 0) {
cs = win - 5300;
ex = Exs[wi];
if (cs < 0)
ex += (Fss[wi] > -cs ? -cs : Fss[wi]);
else
ex += (cs > Tss[wi] ? Tss[wi] : cs);
cs -= Tss[wi] - Fss[wi];
cs += 5300;
if (cs < 0) cs = 0;
if (cs > 5300 * 2) cs = 5300 * 2;
if (ex + DPF[wic][win] > DPB[wic + 1][cs])
DPB[wic + 1][cs] = ex + DPF[wic][win];
}
for (win = 0; win <= 5300 * 2; ++win)
Max = ((Max) > (DPB[K][win]) ? (Max) : (DPB[K][win]));
memcpy(DPF, DPB, sizeof(DPF));
}
}
int main() {
scanf("%d %d", &N, &K);
int wi;
for (wi = 1; wi <= N; ++wi) std::cin >> Arr[wi];
for (wi = 1; wi <= N; ++wi) {
while ((Arr[wi] % 2) == 0) {
++Tss[wi];
Arr[wi] /= 2;
}
while ((Arr[wi] % 5) == 0) {
++Fss[wi];
Arr[wi] /= 5;
}
Exs[wi] = (Fss[wi] > Tss[wi] ? Tss[wi] : Fss[wi]);
Tss[wi] -= Exs[wi];
Fss[wi] -= Exs[wi];
}
DPA();
printf("%d\n", Max);
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
int Tss[210], Fss[210], Exs[210];
long long Arr[210];
int N, K;
int DPF[210][5300 * 2 + 10], DPB[210][5300 * 2 + 10];
int Max;
void DPA() {
int wi;
int wic, win;
int cs, ex;
memset(DPF, -0x3F, sizeof(DPF));
memset(DPB, -0x3F, sizeof(DPB));
DPF[0][5300] = DPB[0][5300] = 0;
for (wi = 1; wi <= N; ++wi) {
for (wic = 0; wic <= (K > wi ? wi : K); ++wic)
for (win = 0; win <= 5300 * 2; ++win)
if (DPF[wic][win] >= 0) {
cs = win - 5300;
ex = Exs[wi];
if (cs < 0)
ex += (Fss[wi] > -cs ? -cs : Fss[wi]);
else
ex += (cs > Tss[wi] ? Tss[wi] : cs);
cs -= Tss[wi] - Fss[wi];
cs += 5300;
if (cs < 0) cs = 0;
if (cs > 5300 * 2) cs = 5300 * 2;
if (ex + DPF[wic][win] > DPB[wic + 1][cs])
DPB[wic + 1][cs] = ex + DPF[wic][win];
}
for (win = 0; win <= 5300 * 2; ++win)
Max = ((Max) > (DPB[K][win]) ? (Max) : (DPB[K][win]));
memcpy(DPF, DPB, sizeof(DPF));
}
}
int main() {
scanf("%d %d", &N, &K);
int wi;
for (wi = 1; wi <= N; ++wi) std::cin >> Arr[wi];
for (wi = 1; wi <= N; ++wi) {
while ((Arr[wi] % 2) == 0) {
++Tss[wi];
Arr[wi] /= 2;
}
while ((Arr[wi] % 5) == 0) {
++Fss[wi];
Arr[wi] /= 5;
}
Exs[wi] = (Fss[wi] > Tss[wi] ? Tss[wi] : Fss[wi]);
Tss[wi] -= Exs[wi];
Fss[wi] -= Exs[wi];
}
DPA();
printf("%d\n", Max);
}
``` |
#include <bits/stdc++.h>
using namespace std;
const double sn = 1e-6;
const int siz = 100005;
int n, k;
pair<int, int> p[205];
long long arr[205];
vector<vector<short>> dp[200];
int solve(int i, int j, int l) {
if (l < 0 || (j == k && l == 0)) return 0;
if (i == n || (k - j) * 26 < l || n - i < k - j || j == k) return -2;
if (dp[i][j][l] != -1) return dp[i][j][l];
int v1 = solve(i + 1, j, l), v2 = solve(i + 1, j + 1, l - p[i].second);
if (v2 != -2) v2 += p[i].first;
return dp[i][j][l] = max(v1, v2);
}
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%I64d", &arr[i]);
long long v1 = arr[i], v2 = arr[i];
while (v1 % 2 == 0) {
p[i].first++;
v1 /= 2;
}
while (v2 % 5 == 0) {
p[i].second++;
v2 /= 5;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= min(i, k); j++) {
dp[i].push_back({});
for (int l = 0; l <= 26 * (k - j); l++) {
dp[i][j].push_back(-1);
}
}
}
int ans = -2;
for (int i = 0; i <= k * 26; i++) {
ans = max(ans, min(i, solve(0, 0, i)));
}
printf("%d\n", ans);
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double sn = 1e-6;
const int siz = 100005;
int n, k;
pair<int, int> p[205];
long long arr[205];
vector<vector<short>> dp[200];
int solve(int i, int j, int l) {
if (l < 0 || (j == k && l == 0)) return 0;
if (i == n || (k - j) * 26 < l || n - i < k - j || j == k) return -2;
if (dp[i][j][l] != -1) return dp[i][j][l];
int v1 = solve(i + 1, j, l), v2 = solve(i + 1, j + 1, l - p[i].second);
if (v2 != -2) v2 += p[i].first;
return dp[i][j][l] = max(v1, v2);
}
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%I64d", &arr[i]);
long long v1 = arr[i], v2 = arr[i];
while (v1 % 2 == 0) {
p[i].first++;
v1 /= 2;
}
while (v2 % 5 == 0) {
p[i].second++;
v2 /= 5;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= min(i, k); j++) {
dp[i].push_back({});
for (int l = 0; l <= 26 * (k - j); l++) {
dp[i][j].push_back(-1);
}
}
}
int ans = -2;
for (int i = 0; i <= k * 26; i++) {
ans = max(ans, min(i, solve(0, 0, i)));
}
printf("%d\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int maxn = 205;
const int maxm = 205 * 64;
int dp[maxn][maxm];
int n, k;
long long in[maxn];
int a[maxn];
int b[maxn];
void fun(int i, long long num) {
int cnt = 0;
while (num % 2 == 0) {
num /= 2;
cnt++;
}
a[i] = cnt;
cnt = 0;
while (num % 5 == 0) {
num /= 5;
cnt++;
}
b[i] = cnt;
}
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> in[i];
fun(i, in[i]);
}
for (int i = 0; i <= k; i++) {
for (int j = 1; j <= maxm; j++) {
dp[i][j] = -INF;
}
}
dp[0][0] = 0;
long long x;
for (int i = 0; i < n; i++) {
for (int j = k; j >= 1; j--)
for (int l = a[i]; l < maxm; l++) {
dp[j][l] = max(dp[j][l], dp[j - 1][l - a[i]] + b[i]);
}
}
int ans = 0;
for (int i = 0; i <= maxm; i++) {
ans = max(ans, min(i, dp[k][i]));
}
cout << ans << endl;
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int maxn = 205;
const int maxm = 205 * 64;
int dp[maxn][maxm];
int n, k;
long long in[maxn];
int a[maxn];
int b[maxn];
void fun(int i, long long num) {
int cnt = 0;
while (num % 2 == 0) {
num /= 2;
cnt++;
}
a[i] = cnt;
cnt = 0;
while (num % 5 == 0) {
num /= 5;
cnt++;
}
b[i] = cnt;
}
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> in[i];
fun(i, in[i]);
}
for (int i = 0; i <= k; i++) {
for (int j = 1; j <= maxm; j++) {
dp[i][j] = -INF;
}
}
dp[0][0] = 0;
long long x;
for (int i = 0; i < n; i++) {
for (int j = k; j >= 1; j--)
for (int l = a[i]; l < maxm; l++) {
dp[j][l] = max(dp[j][l], dp[j - 1][l - a[i]] + b[i]);
}
}
int ans = 0;
for (int i = 0; i <= maxm; i++) {
ans = max(ans, min(i, dp[k][i]));
}
cout << ans << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[205];
long long b[205], c[205];
long long dp[2][205][5005];
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (long long(i) = (1); (i) <= (n); (i)++) {
cin >> a[i];
while (a[i] % 2 == 0) b[i]++, a[i] /= 2;
while (a[i] % 5 == 0) c[i]++, a[i] /= 5;
}
for (long long(j) = (0); (j) <= (k); (j)++)
for (long long(l) = (0); (l) <= (5000); (l)++) dp[0][j][l] = -1e9;
dp[0][0][0] = 0;
for (long long(i) = (0); (i) <= (n - 1); (i)++) {
for (long long(j) = (0); (j) <= (k); (j)++)
for (long long(l) = (0); (l) <= (5000); (l)++)
dp[(i + 1) & 1][j][l] = -1e9;
for (long long(j) = (0); (j) <= (k); (j)++) {
for (long long(l) = (0); (l) <= (5000); (l)++) {
(dp[(i + 1) & 1][j][l]) =
max((dp[(i + 1) & 1][j][l]), (dp[i & 1][j][l]));
if (j + 1 <= k && l + c[i + 1] <= 5000) {
(dp[(i + 1) & 1][j + 1][l + c[i + 1]]) =
max((dp[(i + 1) & 1][j + 1][l + c[i + 1]]),
(dp[i & 1][j][l] + b[i + 1]));
}
}
}
}
long long ans = 0;
for (long long(i) = (0); (i) <= (5000); (i)++)
(ans) = max((ans), (min(dp[n % 2][k][i], i)));
cout << ans << endl;
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[205];
long long b[205], c[205];
long long dp[2][205][5005];
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (long long(i) = (1); (i) <= (n); (i)++) {
cin >> a[i];
while (a[i] % 2 == 0) b[i]++, a[i] /= 2;
while (a[i] % 5 == 0) c[i]++, a[i] /= 5;
}
for (long long(j) = (0); (j) <= (k); (j)++)
for (long long(l) = (0); (l) <= (5000); (l)++) dp[0][j][l] = -1e9;
dp[0][0][0] = 0;
for (long long(i) = (0); (i) <= (n - 1); (i)++) {
for (long long(j) = (0); (j) <= (k); (j)++)
for (long long(l) = (0); (l) <= (5000); (l)++)
dp[(i + 1) & 1][j][l] = -1e9;
for (long long(j) = (0); (j) <= (k); (j)++) {
for (long long(l) = (0); (l) <= (5000); (l)++) {
(dp[(i + 1) & 1][j][l]) =
max((dp[(i + 1) & 1][j][l]), (dp[i & 1][j][l]));
if (j + 1 <= k && l + c[i + 1] <= 5000) {
(dp[(i + 1) & 1][j + 1][l + c[i + 1]]) =
max((dp[(i + 1) & 1][j + 1][l + c[i + 1]]),
(dp[i & 1][j][l] + b[i + 1]));
}
}
}
}
long long ans = 0;
for (long long(i) = (0); (i) <= (5000); (i)++)
(ans) = max((ans), (min(dp[n % 2][k][i], i)));
cout << ans << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int Xp5 = 5229, Xn = 256;
int dp[Xn][Xp5];
int main() {
int n, k;
cin >> n >> k;
vector<pair<int, int> > V(n);
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
while (!(x % 2)) {
x /= 2;
V[i].first++;
}
while (!(x % 5)) {
x /= 5;
V[i].second++;
}
}
for (int i = 0; i <= k; i++)
for (int j = 0; j < Xp5; j++) dp[i][j] = -12345;
dp[0][0] = 0;
for (int i = 0; i < n; i++)
for (int c = k; c; c--)
for (int p5 = V[i].second; p5 < Xp5; p5++)
dp[c][p5] = max(dp[c][p5], dp[c - 1][p5 - V[i].second] + V[i].first);
int a = 0;
for (int p5 = 0; p5 < Xp5; p5++)
a = max(a, dp[k][p5] ? min(dp[k][p5], p5) : 0);
cout << a << "\n";
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int Xp5 = 5229, Xn = 256;
int dp[Xn][Xp5];
int main() {
int n, k;
cin >> n >> k;
vector<pair<int, int> > V(n);
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
while (!(x % 2)) {
x /= 2;
V[i].first++;
}
while (!(x % 5)) {
x /= 5;
V[i].second++;
}
}
for (int i = 0; i <= k; i++)
for (int j = 0; j < Xp5; j++) dp[i][j] = -12345;
dp[0][0] = 0;
for (int i = 0; i < n; i++)
for (int c = k; c; c--)
for (int p5 = V[i].second; p5 < Xp5; p5++)
dp[c][p5] = max(dp[c][p5], dp[c - 1][p5 - V[i].second] + V[i].first);
int a = 0;
for (int p5 = 0; p5 < Xp5; p5++)
a = max(a, dp[k][p5] ? min(dp[k][p5], p5) : 0);
cout << a << "\n";
}
``` |
#include <bits/stdc++.h>
using namespace std;
int dp[2][202][202 * 28];
int cal(long long n, long long m) {
int ret = 0;
while (n % m == 0) {
n /= m;
ret++;
}
return ret;
}
int main() {
int n, k, i, j, l, five, two, m;
long long x;
scanf("%d", &n);
scanf("%d", &k);
m = 28 * n;
for (i = 0; i <= n; ++i) {
for (j = 0; j <= m; ++j) {
dp[0][i][j] = -1000000;
dp[1][i][j] = -1000000;
}
}
for (j = 0; j <= k; j++) {
dp[0][j][0] = 0;
dp[1][j][0] = 0;
}
for (i = 1; i <= n; ++i) {
scanf("%lld", &x);
five = cal(x, 5);
two = cal(x, 2);
for (j = 1; j <= k; ++j) {
for (l = 0; l <= m; ++l) {
if (l - five >= 0) {
dp[i & 1][j][l] = max(dp[(i - 1) & 1][j - 1][l - five] + two,
dp[(i - 1) & 1][j][l]);
} else {
dp[i & 1][j][l] = dp[(i - 1) & 1][j][l];
}
}
}
}
int ans = 0;
for (i = 0; i <= m; ++i) {
ans = max(ans, min(dp[n & 1][k][i], i));
}
printf("%d\n", ans);
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[2][202][202 * 28];
int cal(long long n, long long m) {
int ret = 0;
while (n % m == 0) {
n /= m;
ret++;
}
return ret;
}
int main() {
int n, k, i, j, l, five, two, m;
long long x;
scanf("%d", &n);
scanf("%d", &k);
m = 28 * n;
for (i = 0; i <= n; ++i) {
for (j = 0; j <= m; ++j) {
dp[0][i][j] = -1000000;
dp[1][i][j] = -1000000;
}
}
for (j = 0; j <= k; j++) {
dp[0][j][0] = 0;
dp[1][j][0] = 0;
}
for (i = 1; i <= n; ++i) {
scanf("%lld", &x);
five = cal(x, 5);
two = cal(x, 2);
for (j = 1; j <= k; ++j) {
for (l = 0; l <= m; ++l) {
if (l - five >= 0) {
dp[i & 1][j][l] = max(dp[(i - 1) & 1][j - 1][l - five] + two,
dp[(i - 1) & 1][j][l]);
} else {
dp[i & 1][j][l] = dp[(i - 1) & 1][j][l];
}
}
}
}
int ans = 0;
for (i = 0; i <= m; ++i) {
ans = max(ans, min(dp[n & 1][k][i], i));
}
printf("%d\n", ans);
}
``` |
#include <bits/stdc++.h>
using namespace std;
int dp[5005][201][2] = {0}, a[201][2] = {0};
bool t[5005] = {1};
void f(long long b, int i) {
while (b % 2 == 0) b /= 2, a[i][0]++;
while (b % 5 == 0) b /= 5, a[i][1]++;
}
int main() {
long long n, k, x;
cin >> n >> k;
dp[0][0][0] = 1;
for (long long i = 0; i < n; ++i) {
cin >> x, f(x, i);
for (int j = min(i + 1, k); j; --j)
for (int o = 5000; o >= a[i][1]; o--)
if (dp[o - a[i][1]][j - 1][0])
dp[o][j][1] = max(dp[o - a[i][1]][j - 1][1] + a[i][0], dp[o][j][1]),
dp[o][j][0] = 1;
}
int m = 0;
for (int i = 0; i <= 5000; ++i) m = max(min(dp[i][k][1], i), m);
printf("%d", m);
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[5005][201][2] = {0}, a[201][2] = {0};
bool t[5005] = {1};
void f(long long b, int i) {
while (b % 2 == 0) b /= 2, a[i][0]++;
while (b % 5 == 0) b /= 5, a[i][1]++;
}
int main() {
long long n, k, x;
cin >> n >> k;
dp[0][0][0] = 1;
for (long long i = 0; i < n; ++i) {
cin >> x, f(x, i);
for (int j = min(i + 1, k); j; --j)
for (int o = 5000; o >= a[i][1]; o--)
if (dp[o - a[i][1]][j - 1][0])
dp[o][j][1] = max(dp[o - a[i][1]][j - 1][1] + a[i][0], dp[o][j][1]),
dp[o][j][0] = 1;
}
int m = 0;
for (int i = 0; i <= 5000; ++i) m = max(min(dp[i][k][1], i), m);
printf("%d", m);
}
``` |
#include <bits/stdc++.h>
using namespace std;
void re() { vector<int> b(1e10); }
const int N = 209;
const int F = 26;
int dp[2][N][F * N];
void get25(long long n, int &two, int &five) {
while (n % 2LL == 0) {
n /= 2LL;
two++;
}
while (n % 5LL == 0) {
n /= 5LL;
five++;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n, K;
cin >> n >> K;
vector<long long> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
int p = 0;
int c = 1;
dp[p][0][0] = 1;
int ans = 0;
for (int i = 0; i < n; ++i, swap(p, c)) {
for (int k = 0; k < N; ++k)
for (int f = 0; f < F * N; ++f) dp[c][k][f] = 0;
int two = 0;
int five = 0;
get25(a[i], two, five);
for (int k = 0; k <= K; ++k) {
for (int f = 0; f < F * N; ++f) {
dp[c][k][f] = dp[p][k][f];
if (f - five >= 0 && dp[p][k - 1][f - five] && k - 1 >= 0) {
dp[c][k][f] = max(dp[c][k][f], dp[p][k - 1][f - five] + two);
}
if (dp[c][k][f]) {
ans = max(ans, min(f, dp[c][k][f] - 1));
}
}
}
}
cout << ans;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void re() { vector<int> b(1e10); }
const int N = 209;
const int F = 26;
int dp[2][N][F * N];
void get25(long long n, int &two, int &five) {
while (n % 2LL == 0) {
n /= 2LL;
two++;
}
while (n % 5LL == 0) {
n /= 5LL;
five++;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n, K;
cin >> n >> K;
vector<long long> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
int p = 0;
int c = 1;
dp[p][0][0] = 1;
int ans = 0;
for (int i = 0; i < n; ++i, swap(p, c)) {
for (int k = 0; k < N; ++k)
for (int f = 0; f < F * N; ++f) dp[c][k][f] = 0;
int two = 0;
int five = 0;
get25(a[i], two, five);
for (int k = 0; k <= K; ++k) {
for (int f = 0; f < F * N; ++f) {
dp[c][k][f] = dp[p][k][f];
if (f - five >= 0 && dp[p][k - 1][f - five] && k - 1 >= 0) {
dp[c][k][f] = max(dp[c][k][f], dp[p][k - 1][f - five] + two);
}
if (dp[c][k][f]) {
ans = max(ans, min(f, dp[c][k][f] - 1));
}
}
}
}
cout << ans;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long MXN = 205;
const long long MX5 = MXN * 27;
long long n, k;
long long dp[MXN][MX5];
int main() {
memset(dp, ~0x3f, sizeof(dp));
dp[0][0] = 0;
scanf("%lld%lld", &n, &k);
for (long long i = 1; i <= n; i++) {
long long tmp, c2 = 0, c5 = 0;
scanf("%lld", &tmp);
while (!(tmp & 1)) {
tmp >>= 1;
c2++;
}
while (!(tmp % 5)) {
tmp /= 5;
c5++;
}
for (long long j = min(i, k); j; j--)
for (long long l = MX5 - 1; l >= c5; l--)
dp[j][l] = max(dp[j][l], dp[j - 1][l - c5] + c2);
}
long long ans = 0;
for (long long i = 1; i < MX5; i++) ans = max(ans, min(i, dp[k][i]));
printf("%lld", ans);
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MXN = 205;
const long long MX5 = MXN * 27;
long long n, k;
long long dp[MXN][MX5];
int main() {
memset(dp, ~0x3f, sizeof(dp));
dp[0][0] = 0;
scanf("%lld%lld", &n, &k);
for (long long i = 1; i <= n; i++) {
long long tmp, c2 = 0, c5 = 0;
scanf("%lld", &tmp);
while (!(tmp & 1)) {
tmp >>= 1;
c2++;
}
while (!(tmp % 5)) {
tmp /= 5;
c5++;
}
for (long long j = min(i, k); j; j--)
for (long long l = MX5 - 1; l >= c5; l--)
dp[j][l] = max(dp[j][l], dp[j - 1][l - c5] + c2);
}
long long ans = 0;
for (long long i = 1; i < MX5; i++) ans = max(ans, min(i, dp[k][i]));
printf("%lld", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long t, f;
node() { t = f = 0; }
node(long long T, long long F) { t = T, f = F; }
} p[205];
long long n, k, a[205], dp[2][205][5005];
node get(long long x) {
long long t = 0, f = 0;
long long tmp = x;
while (x % 2 == 0) ++t, x /= 2;
x = tmp;
while (x % 5 == 0) ++f, x /= 5;
return {t, f};
}
int main() {
cin >> n >> k;
for (long long i = 1; i <= n; ++i) {
cin >> a[i];
}
memset(dp, -1, sizeof dp);
dp[0][0][0] = 0;
long long up = 0;
for (long long i = 1; i <= n; ++i) {
long long now = i & 1;
p[i] = get(a[i]);
up += p[i].f;
for (long long j = 0; j <= min(i, k); ++j) {
for (long long l = 0; l <= up; ++l) {
dp[now][j][l] = dp[now ^ 1][j][l];
if (j && l >= p[i].f && ~dp[now ^ 1][j - 1][l - p[i].f])
dp[now][j][l] =
max(dp[now][j][l], dp[now ^ 1][j - 1][l - p[i].f] + p[i].t);
}
}
}
long long ans = 0;
for (long long i = 0; i <= up; ++i) ans = max(ans, min(i, dp[n & 1][k][i]));
cout << ans;
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct node {
long long t, f;
node() { t = f = 0; }
node(long long T, long long F) { t = T, f = F; }
} p[205];
long long n, k, a[205], dp[2][205][5005];
node get(long long x) {
long long t = 0, f = 0;
long long tmp = x;
while (x % 2 == 0) ++t, x /= 2;
x = tmp;
while (x % 5 == 0) ++f, x /= 5;
return {t, f};
}
int main() {
cin >> n >> k;
for (long long i = 1; i <= n; ++i) {
cin >> a[i];
}
memset(dp, -1, sizeof dp);
dp[0][0][0] = 0;
long long up = 0;
for (long long i = 1; i <= n; ++i) {
long long now = i & 1;
p[i] = get(a[i]);
up += p[i].f;
for (long long j = 0; j <= min(i, k); ++j) {
for (long long l = 0; l <= up; ++l) {
dp[now][j][l] = dp[now ^ 1][j][l];
if (j && l >= p[i].f && ~dp[now ^ 1][j - 1][l - p[i].f])
dp[now][j][l] =
max(dp[now][j][l], dp[now ^ 1][j - 1][l - p[i].f] + p[i].t);
}
}
}
long long ans = 0;
for (long long i = 0; i <= up; ++i) ans = max(ans, min(i, dp[n & 1][k][i]));
cout << ans;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int dp[201][200 * 25 + 1];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i <= k; ++i)
for (int j = 0; j < 200 * 25 + 1; ++j) dp[i][j] = INT_MIN;
dp[0][0] = 0;
for (int tx = 1; tx <= n; ++tx) {
long long a;
int x = 0, y = 0;
cin >> a;
while (a % 2 == 0) ++x, a /= 2;
while (a % 5 == 0) ++y, a /= 5;
for (int i = k; i > 0; --i)
for (int j = 200 * 25 + 1 - 1; j >= y; --j)
dp[i][j] = max(dp[i][j], dp[i - 1][j - y] + x);
}
int ans = 0;
for (int j = 0; j < 200 * 25 + 1; ++j) ans = max(ans, min(j, dp[k][j]));
cout << ans << '\n';
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[201][200 * 25 + 1];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i <= k; ++i)
for (int j = 0; j < 200 * 25 + 1; ++j) dp[i][j] = INT_MIN;
dp[0][0] = 0;
for (int tx = 1; tx <= n; ++tx) {
long long a;
int x = 0, y = 0;
cin >> a;
while (a % 2 == 0) ++x, a /= 2;
while (a % 5 == 0) ++y, a /= 5;
for (int i = k; i > 0; --i)
for (int j = 200 * 25 + 1 - 1; j >= y; --j)
dp[i][j] = max(dp[i][j], dp[i - 1][j - y] + x);
}
int ans = 0;
for (int j = 0; j < 200 * 25 + 1; ++j) ans = max(ans, min(j, dp[k][j]));
cout << ans << '\n';
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e14;
const int mod = (int)1e9 + 7;
const int N = (int)100100;
const double eps = 1e-10;
const double pi = acos(-1.0);
long long a[N], dp[2][201][5300], pw5[201], pw2[201];
long long five(long long x) {
long long cnt = 0;
while (x % 5 == 0) {
cnt++;
x /= 5;
}
return cnt;
}
long long two(long long x) {
long long cnt = 0;
while (x % 2 == 0) {
cnt++;
x /= 2;
}
return cnt;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pw2[i] = two(a[i]);
pw5[i] = five(a[i]);
}
for (int i = 0; i <= 1; i++) {
for (int j = 0; j <= 200; j++) {
for (int t = 0; t <= 5200; t++) {
dp[i][j][t] = -inf;
}
}
}
dp[1][1][pw5[1]] = pw2[1];
dp[1][0][0] = 0;
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= min((long long)i, k); j++) {
for (int t = 0; t <= 5200; t++) {
int cur = (i & 1);
int prev = ((i - 1) & 1);
if (t - pw5[i] >= 0 && j > 0) {
dp[cur][j][t] =
max(dp[cur][j][t], dp[prev][j - 1][t - pw5[i]] + pw2[i]);
}
dp[cur][j][t] = max(dp[cur][j][t], dp[prev][j][t]);
}
}
for (int j = 0; j <= k; j++) {
for (int t = 0; t <= 5200; t++) {
int prev = ((i - 1) & 1);
dp[prev][j][t] = -inf;
}
}
}
int cur = (n & 1);
long long ans = 0;
for (int i = 0; i <= 5200; i++) {
long long deg = min((long long)i, dp[cur][k][i]);
ans = max(ans, deg);
}
cout << ans;
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e14;
const int mod = (int)1e9 + 7;
const int N = (int)100100;
const double eps = 1e-10;
const double pi = acos(-1.0);
long long a[N], dp[2][201][5300], pw5[201], pw2[201];
long long five(long long x) {
long long cnt = 0;
while (x % 5 == 0) {
cnt++;
x /= 5;
}
return cnt;
}
long long two(long long x) {
long long cnt = 0;
while (x % 2 == 0) {
cnt++;
x /= 2;
}
return cnt;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pw2[i] = two(a[i]);
pw5[i] = five(a[i]);
}
for (int i = 0; i <= 1; i++) {
for (int j = 0; j <= 200; j++) {
for (int t = 0; t <= 5200; t++) {
dp[i][j][t] = -inf;
}
}
}
dp[1][1][pw5[1]] = pw2[1];
dp[1][0][0] = 0;
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= min((long long)i, k); j++) {
for (int t = 0; t <= 5200; t++) {
int cur = (i & 1);
int prev = ((i - 1) & 1);
if (t - pw5[i] >= 0 && j > 0) {
dp[cur][j][t] =
max(dp[cur][j][t], dp[prev][j - 1][t - pw5[i]] + pw2[i]);
}
dp[cur][j][t] = max(dp[cur][j][t], dp[prev][j][t]);
}
}
for (int j = 0; j <= k; j++) {
for (int t = 0; t <= 5200; t++) {
int prev = ((i - 1) & 1);
dp[prev][j][t] = -inf;
}
}
}
int cur = (n & 1);
long long ans = 0;
for (int i = 0; i <= 5200; i++) {
long long deg = min((long long)i, dp[cur][k][i]);
ans = max(ans, deg);
}
cout << ans;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
os << p.first << " " << p.second;
return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
for (T i : v) os << i << ", ";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> second) {
for (T i : second) os << i << ", ";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> m) {
for (pair<T1, T2> i : m) os << i << "\n";
return os;
}
long long N, K;
long long a[200];
long long dp[2][5200][200];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> K;
fill(dp[0][0], dp[1][5199] + 200, -1e9);
long long mxidx = 0;
long long ans = 0;
for (long long i = 0; i < N; i++) {
cin >> a[i];
long long two = 0;
while (a[i] % 2 == 0) {
two++;
a[i] /= 2;
}
long long five = 0;
while (a[i] % 5 == 0) {
five++;
a[i] /= 5;
}
long long m1 = i % 2;
long long m2 = !m1;
mxidx += five;
for (long long j = 0; j <= mxidx; j++) {
for (long long k = 0; k <= min(K - 1, i); k++) {
dp[m1][j][k] = dp[m2][j][k];
}
}
dp[m1][five][0] = max(dp[m2][five][0], two);
for (long long j = five; j <= mxidx; j++) {
for (long long k = 1; k <= min(K - 1, i); k++) {
dp[m1][j][k] = max(dp[m2][j][k], dp[m2][j - five][k - 1] + two);
}
for (long long k = 0; k <= min(K - 1, i); k++) {
ans = max(ans, min(dp[m1][j][k], j));
}
}
}
cout << ans << "\n";
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
os << p.first << " " << p.second;
return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
for (T i : v) os << i << ", ";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> second) {
for (T i : second) os << i << ", ";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> m) {
for (pair<T1, T2> i : m) os << i << "\n";
return os;
}
long long N, K;
long long a[200];
long long dp[2][5200][200];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> K;
fill(dp[0][0], dp[1][5199] + 200, -1e9);
long long mxidx = 0;
long long ans = 0;
for (long long i = 0; i < N; i++) {
cin >> a[i];
long long two = 0;
while (a[i] % 2 == 0) {
two++;
a[i] /= 2;
}
long long five = 0;
while (a[i] % 5 == 0) {
five++;
a[i] /= 5;
}
long long m1 = i % 2;
long long m2 = !m1;
mxidx += five;
for (long long j = 0; j <= mxidx; j++) {
for (long long k = 0; k <= min(K - 1, i); k++) {
dp[m1][j][k] = dp[m2][j][k];
}
}
dp[m1][five][0] = max(dp[m2][five][0], two);
for (long long j = five; j <= mxidx; j++) {
for (long long k = 1; k <= min(K - 1, i); k++) {
dp[m1][j][k] = max(dp[m2][j][k], dp[m2][j - five][k - 1] + two);
}
for (long long k = 0; k <= min(K - 1, i); k++) {
ans = max(ans, min(dp[m1][j][k], j));
}
}
}
cout << ans << "\n";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 202;
int a[N][2];
int dp[2][N][5003];
int main() {
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
long long v;
cin >> v;
int cnt = 0;
while (v % 2 == 0) {
v /= 2;
cnt++;
}
a[i][0] = cnt;
cnt = 0;
while (v % 5 == 0) {
v /= 5;
cnt++;
}
a[i][1] = cnt;
}
int ans = 0;
memset(dp, -1, sizeof dp);
for (int i = 0; i <= n; i++) dp[0][i][0] = 0;
for (int z = 1; z <= k; z++) {
int s = z % 2;
for (int i = 1; i <= n; i++) {
int t = a[i][0], f = a[i][1];
for (int j = 0; j <= 5000; j++) {
dp[s][i][j] = dp[s][i - 1][j];
if (f <= j) {
if (dp[!s][i - 1][j - f] != -1)
dp[s][i][j] = max(dp[!s][i - 1][j - f] + t, dp[s][i][j]);
}
ans = max(ans, min(j, dp[s][i][j]));
}
}
}
cout << ans;
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 202;
int a[N][2];
int dp[2][N][5003];
int main() {
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
long long v;
cin >> v;
int cnt = 0;
while (v % 2 == 0) {
v /= 2;
cnt++;
}
a[i][0] = cnt;
cnt = 0;
while (v % 5 == 0) {
v /= 5;
cnt++;
}
a[i][1] = cnt;
}
int ans = 0;
memset(dp, -1, sizeof dp);
for (int i = 0; i <= n; i++) dp[0][i][0] = 0;
for (int z = 1; z <= k; z++) {
int s = z % 2;
for (int i = 1; i <= n; i++) {
int t = a[i][0], f = a[i][1];
for (int j = 0; j <= 5000; j++) {
dp[s][i][j] = dp[s][i - 1][j];
if (f <= j) {
if (dp[!s][i - 1][j - f] != -1)
dp[s][i][j] = max(dp[!s][i - 1][j - f] + t, dp[s][i][j]);
}
ans = max(ans, min(j, dp[s][i][j]));
}
}
}
cout << ans;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long i, i1, j, k, k1, t, n, m, res, flag[10], a[210], b, dp[2][210][5210],
p[210][2];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k1;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++) {
p[i][0] = 0;
p[i][1] = 0;
while (a[i] % 2 == 0) {
a[i] /= 2;
p[i][0]++;
}
while (a[i] % 5 == 0) {
a[i] /= 5;
p[i][1]++;
}
}
res = 0;
for (i = 0; i < 2; i++) {
for (j = 0; j <= n; j++) {
for (k = 0; k < 5210; k++) {
dp[i][j][k] = -(long long)1e18;
}
}
}
dp[0][0][0] = 0;
for (i = 1; i <= n; i++) {
for (j = 0; j <= n; j++) {
for (k = 0; k < 5210; k++) {
dp[1][j][k] = max(dp[1][j][k], dp[0][j][k]);
if (k >= p[i][1] && j >= 1) {
dp[1][j][k] = max(dp[1][j][k], dp[0][j - 1][k - p[i][1]] + p[i][0]);
}
if (j == k1) res = max(res, min(dp[1][j][k], k));
}
}
for (j = 0; j <= n; j++) {
for (k = 0; k < 5210; k++) {
dp[0][j][k] = dp[1][j][k];
}
}
}
cout << res;
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long i, i1, j, k, k1, t, n, m, res, flag[10], a[210], b, dp[2][210][5210],
p[210][2];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k1;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++) {
p[i][0] = 0;
p[i][1] = 0;
while (a[i] % 2 == 0) {
a[i] /= 2;
p[i][0]++;
}
while (a[i] % 5 == 0) {
a[i] /= 5;
p[i][1]++;
}
}
res = 0;
for (i = 0; i < 2; i++) {
for (j = 0; j <= n; j++) {
for (k = 0; k < 5210; k++) {
dp[i][j][k] = -(long long)1e18;
}
}
}
dp[0][0][0] = 0;
for (i = 1; i <= n; i++) {
for (j = 0; j <= n; j++) {
for (k = 0; k < 5210; k++) {
dp[1][j][k] = max(dp[1][j][k], dp[0][j][k]);
if (k >= p[i][1] && j >= 1) {
dp[1][j][k] = max(dp[1][j][k], dp[0][j - 1][k - p[i][1]] + p[i][0]);
}
if (j == k1) res = max(res, min(dp[1][j][k], k));
}
}
for (j = 0; j <= n; j++) {
for (k = 0; k < 5210; k++) {
dp[0][j][k] = dp[1][j][k];
}
}
}
cout << res;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
long long quick_pow(long long x, long long y) {
long long ans = 1;
while (y) {
if (y & 1) {
ans = ans * x % mod;
}
x = x * x % mod;
y >>= 1;
}
return ans;
}
struct node {
int cnt2;
int cnt5;
} a[maxn];
int dp[205][205 * 64];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
long long x;
scanf("%lld", &x);
while (x % 2 == 0) {
a[i].cnt2++;
x /= 2;
}
while (x % 5 == 0) {
a[i].cnt5++;
x /= 5;
}
}
long long sum = 0;
memset(dp, -INF, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
sum += a[i].cnt5;
for (int j = min(k, i); j >= 1; j--) {
for (int k = sum; k >= a[i].cnt5; k--) {
dp[j][k] = max(dp[j][k], dp[j - 1][k - a[i].cnt5] + a[i].cnt2);
}
}
}
long long ans = 0;
for (int i = 1; i <= sum; i++) {
ans = max(ans, 1LL * min(i, dp[k][i]));
}
printf("%lld\n", ans);
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
long long quick_pow(long long x, long long y) {
long long ans = 1;
while (y) {
if (y & 1) {
ans = ans * x % mod;
}
x = x * x % mod;
y >>= 1;
}
return ans;
}
struct node {
int cnt2;
int cnt5;
} a[maxn];
int dp[205][205 * 64];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
long long x;
scanf("%lld", &x);
while (x % 2 == 0) {
a[i].cnt2++;
x /= 2;
}
while (x % 5 == 0) {
a[i].cnt5++;
x /= 5;
}
}
long long sum = 0;
memset(dp, -INF, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
sum += a[i].cnt5;
for (int j = min(k, i); j >= 1; j--) {
for (int k = sum; k >= a[i].cnt5; k--) {
dp[j][k] = max(dp[j][k], dp[j - 1][k - a[i].cnt5] + a[i].cnt2);
}
}
}
long long ans = 0;
for (int i = 1; i <= sum; i++) {
ans = max(ans, 1LL * min(i, dp[k][i]));
}
printf("%lld\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 201;
const int inf = 70 * N;
int n, k, a[N][2], f[N][N * 18];
template <class T>
inline void cmax(T& x, T y) {
if (y > x) x = y;
}
int main() {
int i, j, t;
scanf("%d%d", &n, &k);
for (i = 1; i <= n; ++i) {
long long x, y;
scanf("%I64d", &x);
for (y = x; !(x & 1LL); x >>= 1) ++a[i][0];
for (x = y; !(x % 5LL); x /= 5LL) ++a[i][1];
}
int T = 18 * n;
for (j = 0; j <= k; ++j)
for (t = 0; t <= T; ++t) f[j][t] = -inf;
f[0][0] = 0;
for (i = 1; i <= n; ++i) {
for (j = k; j; --j) {
for (t = max(0, T - a[i][1]); t <= T; ++t) {
cmax(f[j][T], f[j - 1][t] + a[i][0]);
}
for (t = T; t >= a[i][1]; --t) {
cmax(f[j][t], f[j - 1][t - a[i][1]] + a[i][0]);
}
}
}
int ans = 0;
for (t = 0; t <= T; ++t) cmax(ans, min(f[k][t], t));
printf("%d", ans);
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 201;
const int inf = 70 * N;
int n, k, a[N][2], f[N][N * 18];
template <class T>
inline void cmax(T& x, T y) {
if (y > x) x = y;
}
int main() {
int i, j, t;
scanf("%d%d", &n, &k);
for (i = 1; i <= n; ++i) {
long long x, y;
scanf("%I64d", &x);
for (y = x; !(x & 1LL); x >>= 1) ++a[i][0];
for (x = y; !(x % 5LL); x /= 5LL) ++a[i][1];
}
int T = 18 * n;
for (j = 0; j <= k; ++j)
for (t = 0; t <= T; ++t) f[j][t] = -inf;
f[0][0] = 0;
for (i = 1; i <= n; ++i) {
for (j = k; j; --j) {
for (t = max(0, T - a[i][1]); t <= T; ++t) {
cmax(f[j][T], f[j - 1][t] + a[i][0]);
}
for (t = T; t >= a[i][1]; --t) {
cmax(f[j][t], f[j - 1][t - a[i][1]] + a[i][0]);
}
}
}
int ans = 0;
for (t = 0; t <= T; ++t) cmax(ans, min(f[k][t], t));
printf("%d", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
inline void Swap(long long &x, long long &y) {
long long Temp = x;
x = y;
y = Temp;
}
inline long long Min(long long x, long long y) { return x < y ? x : y; }
inline long long Max(long long x, long long y) { return x > y ? x : y; }
inline void read(long long &x) {
x = 0;
long long f = 1;
char s = getchar();
while (s < '0' || s > '9') {
if (s == '-') f = -1;
s = getchar();
}
while (s >= '0' && s <= '9') {
x = (x << 3) + (x << 1) + (s ^ 48);
s = getchar();
}
x *= f;
}
long long dp[205][205 * 30], a[205], Five[205], Two[205];
inline long long Count(long long x, long long y) {
long long Res = 0;
while (x % y == 0) {
Res++;
x /= y;
}
return Res;
}
int main() {
long long n, k;
read(n);
read(k);
for (register int i = 1; i <= n; ++i) {
read(a[i]);
Five[i] = Count(a[i], 5);
Two[i] = Count(a[i], 2);
}
memset(dp, -1, sizeof dp);
dp[0][0] = 0;
for (register int i = 1; i <= n; ++i)
for (register int j = i; j >= 1; --j)
for (register int k = i * 30; k >= Five[i]; --k)
if (~dp[j - 1][k - Five[i]])
dp[j][k] = Max(dp[j][k], dp[j - 1][k - Five[i]] + Two[i]);
long long Ans = 0;
for (register int i = 1; i <= 30 * n; ++i) Ans = Max(Ans, Min(i, dp[k][i]));
printf("%lld", Ans);
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
inline void Swap(long long &x, long long &y) {
long long Temp = x;
x = y;
y = Temp;
}
inline long long Min(long long x, long long y) { return x < y ? x : y; }
inline long long Max(long long x, long long y) { return x > y ? x : y; }
inline void read(long long &x) {
x = 0;
long long f = 1;
char s = getchar();
while (s < '0' || s > '9') {
if (s == '-') f = -1;
s = getchar();
}
while (s >= '0' && s <= '9') {
x = (x << 3) + (x << 1) + (s ^ 48);
s = getchar();
}
x *= f;
}
long long dp[205][205 * 30], a[205], Five[205], Two[205];
inline long long Count(long long x, long long y) {
long long Res = 0;
while (x % y == 0) {
Res++;
x /= y;
}
return Res;
}
int main() {
long long n, k;
read(n);
read(k);
for (register int i = 1; i <= n; ++i) {
read(a[i]);
Five[i] = Count(a[i], 5);
Two[i] = Count(a[i], 2);
}
memset(dp, -1, sizeof dp);
dp[0][0] = 0;
for (register int i = 1; i <= n; ++i)
for (register int j = i; j >= 1; --j)
for (register int k = i * 30; k >= Five[i]; --k)
if (~dp[j - 1][k - Five[i]])
dp[j][k] = Max(dp[j][k], dp[j - 1][k - Five[i]] + Two[i]);
long long Ans = 0;
for (register int i = 1; i <= 30 * n; ++i) Ans = Max(Ans, Min(i, dp[k][i]));
printf("%lld", Ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const long long MAXN = 100005;
long long n, m, o, a[MAXN], b[MAXN], f[2][205][5005];
int main() {
n = read();
m = read();
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (long long i = (1); i <= (n); ++i) {
long long x = read();
while (x % 2 == 0) a[i]++, x /= 2;
while (x % 5 == 0) b[i]++, x /= 5;
}
memset(f, 0, sizeof(f));
f[0][0][0] = 1;
o = 0;
for (long long i = (1); i <= (n); ++i) {
o = 1 - o;
memset(f[o], 0, sizeof(f[o]));
for (long long j = (0); j <= (i); ++j)
for (long long k = (0); k <= (j * 25); ++k) {
f[o][j][k] = max(f[o][j][k], f[1 - o][j][k]);
if (k >= b[i] && j > 0 && f[1 - o][j - 1][k - b[i]] > 0)
f[o][j][k] = max(f[o][j][k], f[1 - o][j - 1][k - b[i]] + a[i]);
}
}
long long ans = 0;
for (long long i = (0); i <= (m * 25); ++i)
ans = max(ans, min(f[o][m][i] - 1, i));
cout << ans << endl;
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const long long MAXN = 100005;
long long n, m, o, a[MAXN], b[MAXN], f[2][205][5005];
int main() {
n = read();
m = read();
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (long long i = (1); i <= (n); ++i) {
long long x = read();
while (x % 2 == 0) a[i]++, x /= 2;
while (x % 5 == 0) b[i]++, x /= 5;
}
memset(f, 0, sizeof(f));
f[0][0][0] = 1;
o = 0;
for (long long i = (1); i <= (n); ++i) {
o = 1 - o;
memset(f[o], 0, sizeof(f[o]));
for (long long j = (0); j <= (i); ++j)
for (long long k = (0); k <= (j * 25); ++k) {
f[o][j][k] = max(f[o][j][k], f[1 - o][j][k]);
if (k >= b[i] && j > 0 && f[1 - o][j - 1][k - b[i]] > 0)
f[o][j][k] = max(f[o][j][k], f[1 - o][j - 1][k - b[i]] + a[i]);
}
}
long long ans = 0;
for (long long i = (0); i <= (m * 25); ++i)
ans = max(ans, min(f[o][m][i] - 1, i));
cout << ans << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
struct Nod {
long long a;
int x, y;
Nod() { a = x = y = 0; }
} nod[220];
void fun(Nod *p) {
long long x = p->a;
while (x % 2 == 0) {
p->x++;
x /= 2;
}
x = p->a;
while (x % 5 == 0) {
p->y++;
x /= 5;
}
}
int dp[210][18 * 210];
bool vis[220];
int main() {
int n, k, MAXY = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> nod[i].a, fun(&nod[i]), MAXY += nod[i].y;
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = k; j >= 1; j--) {
for (int k = MAXY; k >= 0; k--) {
if (k - nod[i].y < 0) continue;
if (dp[j - 1][k - nod[i].y] == -1) continue;
dp[j][k] = max(dp[j][k], dp[j - 1][k - nod[i].y] + nod[i].x);
}
}
}
int ans = 0;
for (int i = 1; i <= MAXY; i++) {
ans = max(ans, min(i, dp[k][i]));
}
printf("%d\n", ans);
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct Nod {
long long a;
int x, y;
Nod() { a = x = y = 0; }
} nod[220];
void fun(Nod *p) {
long long x = p->a;
while (x % 2 == 0) {
p->x++;
x /= 2;
}
x = p->a;
while (x % 5 == 0) {
p->y++;
x /= 5;
}
}
int dp[210][18 * 210];
bool vis[220];
int main() {
int n, k, MAXY = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> nod[i].a, fun(&nod[i]), MAXY += nod[i].y;
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = k; j >= 1; j--) {
for (int k = MAXY; k >= 0; k--) {
if (k - nod[i].y < 0) continue;
if (dp[j - 1][k - nod[i].y] == -1) continue;
dp[j][k] = max(dp[j][k], dp[j - 1][k - nod[i].y] + nod[i].x);
}
}
}
int ans = 0;
for (int i = 1; i <= MAXY; i++) {
ans = max(ans, min(i, dp[k][i]));
}
printf("%d\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int dp[2][202][28 * 204];
vector<pair<long long int, long long int> > A(202);
int n, k;
int main() {
for (int i = 0; i < 2; i++)
for (int j = 0; j < 202; j++)
for (int l = 0; l < 202 * 28; l++) dp[i][j][l] = -10000000;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
long long int temp;
cin >> temp;
int two = 0, five = 0;
while (temp % 2 == 0) temp = temp / 2, two++;
while (temp % 5 == 0) temp = temp / 5, five++;
A[i].first = two;
A[i].second = five;
}
dp[0][0][0] = 0;
for (int i = 1; i <= n; i++) {
int two = A[i].first;
int five = A[i].second;
for (int j = min(k, i); j >= 0; j--) {
for (int l = 0; l < 202 * 28; l++) {
if (l >= five && j > 0)
dp[i & 1][j][l] =
max(dp[i & 1][j][l], dp[~i & 1][j - 1][l - five] + two);
dp[i & 1][j][l] = max(dp[i & 1][j][l], dp[~i & 1][j][l]);
}
}
}
int ans = 0;
for (int i = 0; i < 202 * 28; i++) {
ans = max(ans, min(i, dp[n & 1][k][i]));
}
cout << ans;
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[2][202][28 * 204];
vector<pair<long long int, long long int> > A(202);
int n, k;
int main() {
for (int i = 0; i < 2; i++)
for (int j = 0; j < 202; j++)
for (int l = 0; l < 202 * 28; l++) dp[i][j][l] = -10000000;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
long long int temp;
cin >> temp;
int two = 0, five = 0;
while (temp % 2 == 0) temp = temp / 2, two++;
while (temp % 5 == 0) temp = temp / 5, five++;
A[i].first = two;
A[i].second = five;
}
dp[0][0][0] = 0;
for (int i = 1; i <= n; i++) {
int two = A[i].first;
int five = A[i].second;
for (int j = min(k, i); j >= 0; j--) {
for (int l = 0; l < 202 * 28; l++) {
if (l >= five && j > 0)
dp[i & 1][j][l] =
max(dp[i & 1][j][l], dp[~i & 1][j - 1][l - five] + two);
dp[i & 1][j][l] = max(dp[i & 1][j][l], dp[~i & 1][j][l]);
}
}
}
int ans = 0;
for (int i = 0; i < 202 * 28; i++) {
ans = max(ans, min(i, dp[n & 1][k][i]));
}
cout << ans;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 205;
const int inf = 1e9 + 7;
struct node {
int two, five;
} bag[maxn];
int sum;
void findcnt(int i, long long val) {
int cnt1 = 0;
while (val % 2 == 0) {
cnt1++;
val /= 2;
}
bag[i].two = cnt1;
cnt1 = 0;
while (val % 5 == 0) {
cnt1++;
val /= 5;
}
bag[i].five = cnt1;
sum += cnt1;
return;
}
int dp[6000][205];
int main() {
int n, k;
scanf("%d%d", &n, &k);
long long temp;
sum = 0;
for (int i = 0; i < n; i++) {
scanf("%lld", &temp);
findcnt(i, temp);
}
for (int i = 0; i <= sum; i++)
for (int j = 0; j <= k; j++) dp[i][j] = -inf;
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int s = sum; s >= bag[i].five; s--) {
for (int j = k; j >= 1; j--) {
if (dp[s - bag[i].five][j - 1] != -inf || s == bag[i].five)
dp[s][j] = max(bag[i].two + dp[s - bag[i].five][j - 1], dp[s][j]);
}
}
}
int ans = 0;
for (int i = sum; i >= 0; i--) ans = max(min(dp[i][k], i), ans);
printf("%d\n", ans);
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 205;
const int inf = 1e9 + 7;
struct node {
int two, five;
} bag[maxn];
int sum;
void findcnt(int i, long long val) {
int cnt1 = 0;
while (val % 2 == 0) {
cnt1++;
val /= 2;
}
bag[i].two = cnt1;
cnt1 = 0;
while (val % 5 == 0) {
cnt1++;
val /= 5;
}
bag[i].five = cnt1;
sum += cnt1;
return;
}
int dp[6000][205];
int main() {
int n, k;
scanf("%d%d", &n, &k);
long long temp;
sum = 0;
for (int i = 0; i < n; i++) {
scanf("%lld", &temp);
findcnt(i, temp);
}
for (int i = 0; i <= sum; i++)
for (int j = 0; j <= k; j++) dp[i][j] = -inf;
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int s = sum; s >= bag[i].five; s--) {
for (int j = k; j >= 1; j--) {
if (dp[s - bag[i].five][j - 1] != -inf || s == bag[i].five)
dp[s][j] = max(bag[i].two + dp[s - bag[i].five][j - 1], dp[s][j]);
}
}
}
int ans = 0;
for (int i = sum; i >= 0; i--) ans = max(min(dp[i][k], i), ans);
printf("%d\n", ans);
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 209;
int dp[N][5001][2], temp[N][5001][2];
int n, k;
int cnt2[N], cnt5[N], cnt[N];
const int oo = (1e9);
const int num_max = 5000;
int main() {
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) {
long long a;
scanf("%I64d", &a);
cnt2[i] = cnt5[i] = 0;
if (a == 0) continue;
while (a % 2 == 0) {
cnt2[i]++;
a /= 2;
}
while (a % 5 == 0) {
cnt5[i]++;
a /= 5;
}
cnt[i] = min(cnt2[i], cnt5[i]);
cnt2[i] -= cnt[i];
cnt5[i] -= cnt[i];
}
int ans = -oo;
for (int t = 0; t <= k; t++)
for (int i = 0; i <= num_max; i++) {
dp[t][i][0] = dp[t][i][1] = -oo;
temp[t][i][0] = temp[t][i][1] = -oo;
}
dp[0][0][0] = dp[0][0][0] = 0;
temp[0][0][0] = temp[0][0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int t = 0; t <= k; t++)
for (int j = 0; j <= num_max; j++) {
dp[t][j][0] = max(dp[t][j][0], temp[t][j][0]);
dp[t][j][1] = max(dp[t][j][1], temp[t][j][1]);
if (t == 0) continue;
if (cnt2[i]) {
int jj = j + cnt2[i];
if (jj > num_max) jj = num_max;
dp[t][jj][0] = max(dp[t][jj][0], temp[t - 1][j][0] + cnt[i]);
jj = j - cnt2[i];
if (jj >= 0) {
dp[t][jj][1] =
max(dp[t][jj][1], temp[t - 1][j][1] + cnt2[i] + cnt[i]);
} else {
jj = abs(jj);
dp[t][jj][0] = max(dp[t][jj][0], temp[t - 1][j][1] + j + cnt[i]);
}
} else {
int jj = j + cnt5[i];
if (jj > num_max) jj = num_max;
dp[t][jj][1] = max(dp[t][jj][1], temp[t - 1][j][1] + cnt[i]);
jj = j - cnt5[i];
if (jj >= 0) {
dp[t][jj][0] =
max(dp[t][jj][0], temp[t - 1][j][0] + cnt5[i] + cnt[i]);
} else {
jj = abs(jj);
dp[t][jj][1] = max(dp[t][jj][1], temp[t - 1][j][0] + j + cnt[i]);
}
}
}
for (int t = 0; t <= k; t++)
for (int j = 0; j <= num_max; j++) {
if (t == k) {
ans = max(ans, dp[t][j][0]);
ans = max(ans, dp[t][j][1]);
}
temp[t][j][0] = dp[t][j][0];
temp[t][j][1] = dp[t][j][1];
dp[t][j][0] = -oo;
dp[t][j][1] = -oo;
}
}
printf("%d", ans);
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 209;
int dp[N][5001][2], temp[N][5001][2];
int n, k;
int cnt2[N], cnt5[N], cnt[N];
const int oo = (1e9);
const int num_max = 5000;
int main() {
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) {
long long a;
scanf("%I64d", &a);
cnt2[i] = cnt5[i] = 0;
if (a == 0) continue;
while (a % 2 == 0) {
cnt2[i]++;
a /= 2;
}
while (a % 5 == 0) {
cnt5[i]++;
a /= 5;
}
cnt[i] = min(cnt2[i], cnt5[i]);
cnt2[i] -= cnt[i];
cnt5[i] -= cnt[i];
}
int ans = -oo;
for (int t = 0; t <= k; t++)
for (int i = 0; i <= num_max; i++) {
dp[t][i][0] = dp[t][i][1] = -oo;
temp[t][i][0] = temp[t][i][1] = -oo;
}
dp[0][0][0] = dp[0][0][0] = 0;
temp[0][0][0] = temp[0][0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int t = 0; t <= k; t++)
for (int j = 0; j <= num_max; j++) {
dp[t][j][0] = max(dp[t][j][0], temp[t][j][0]);
dp[t][j][1] = max(dp[t][j][1], temp[t][j][1]);
if (t == 0) continue;
if (cnt2[i]) {
int jj = j + cnt2[i];
if (jj > num_max) jj = num_max;
dp[t][jj][0] = max(dp[t][jj][0], temp[t - 1][j][0] + cnt[i]);
jj = j - cnt2[i];
if (jj >= 0) {
dp[t][jj][1] =
max(dp[t][jj][1], temp[t - 1][j][1] + cnt2[i] + cnt[i]);
} else {
jj = abs(jj);
dp[t][jj][0] = max(dp[t][jj][0], temp[t - 1][j][1] + j + cnt[i]);
}
} else {
int jj = j + cnt5[i];
if (jj > num_max) jj = num_max;
dp[t][jj][1] = max(dp[t][jj][1], temp[t - 1][j][1] + cnt[i]);
jj = j - cnt5[i];
if (jj >= 0) {
dp[t][jj][0] =
max(dp[t][jj][0], temp[t - 1][j][0] + cnt5[i] + cnt[i]);
} else {
jj = abs(jj);
dp[t][jj][1] = max(dp[t][jj][1], temp[t - 1][j][0] + j + cnt[i]);
}
}
}
for (int t = 0; t <= k; t++)
for (int j = 0; j <= num_max; j++) {
if (t == k) {
ans = max(ans, dp[t][j][0]);
ans = max(ans, dp[t][j][1]);
}
temp[t][j][0] = dp[t][j][0];
temp[t][j][1] = dp[t][j][1];
dp[t][j][0] = -oo;
dp[t][j][1] = -oo;
}
}
printf("%d", ans);
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 201;
const int LIMIT = 25 * MAXN;
int n, k;
int dp[2][MAXN][LIMIT];
long long arr[MAXN];
long long powOf(long long n, long long d) {
long long res = 0;
while (n % d == 0) {
n /= d;
res++;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
memset(dp, -1, sizeof dp);
dp[0][0][0] = 0;
for (int i = 1; i <= n; i++) {
int curr = i & 1;
for (int j = 0; j < MAXN; j++) {
for (int k = 0; k < LIMIT; k++) dp[curr][j][k] = -1;
}
int c2 = powOf(arr[i], 2ll);
int c5 = powOf(arr[i], 5ll);
int upper = min(k, i);
dp[curr][0][0] = 0;
for (int j = 1; j <= upper; j++) {
int LIMIT = 1 + i * 25;
for (int num5 = 0; num5 < LIMIT; num5++) {
if (num5 >= c5 && dp[1 - curr][j - 1][num5 - c5] >= 0)
dp[curr][j][num5] = dp[1 - curr][j - 1][num5 - c5] + c2;
dp[curr][j][num5] = max(dp[curr][j][num5], dp[1 - curr][j][num5]);
}
}
}
int res = 0;
for (int num5 = 0; num5 < LIMIT; num5++) {
if (dp[n & 1][k][num5] > 0) {
res = max(res, min(dp[n & 1][k][num5], num5));
}
}
cout << res << '\n';
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 201;
const int LIMIT = 25 * MAXN;
int n, k;
int dp[2][MAXN][LIMIT];
long long arr[MAXN];
long long powOf(long long n, long long d) {
long long res = 0;
while (n % d == 0) {
n /= d;
res++;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
memset(dp, -1, sizeof dp);
dp[0][0][0] = 0;
for (int i = 1; i <= n; i++) {
int curr = i & 1;
for (int j = 0; j < MAXN; j++) {
for (int k = 0; k < LIMIT; k++) dp[curr][j][k] = -1;
}
int c2 = powOf(arr[i], 2ll);
int c5 = powOf(arr[i], 5ll);
int upper = min(k, i);
dp[curr][0][0] = 0;
for (int j = 1; j <= upper; j++) {
int LIMIT = 1 + i * 25;
for (int num5 = 0; num5 < LIMIT; num5++) {
if (num5 >= c5 && dp[1 - curr][j - 1][num5 - c5] >= 0)
dp[curr][j][num5] = dp[1 - curr][j - 1][num5 - c5] + c2;
dp[curr][j][num5] = max(dp[curr][j][num5], dp[1 - curr][j][num5]);
}
}
}
int res = 0;
for (int num5 = 0; num5 < LIMIT; num5++) {
if (dp[n & 1][k][num5] > 0) {
res = max(res, min(dp[n & 1][k][num5], num5));
}
}
cout << res << '\n';
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int inf = 210;
const int max_n = 210;
const int max_size2 = 205 * 64;
const int max_size5 = 205 * 35;
short int c_5[max_n], c_2[max_n];
short int dp[max_size2][max_size5];
int main() {
int n, t;
cin >> n >> t;
int sum2 = 0;
int sum5 = 0;
for (int i = 0; i < n; i++) {
long long a;
cin >> a;
long long tmp = a;
while (tmp % 2 == 0) c_2[i]++, tmp /= 2;
tmp = a;
while (tmp % 5 == 0) c_5[i]++, tmp /= 5;
}
for (int i = 0; i < max_size2; i++)
for (int j = 0; j < max_size5; j++) dp[i][j] = inf;
dp[0][0] = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
sum2 += c_2[i];
sum5 += c_5[i];
for (int j = sum2; j >= c_2[i]; j--)
for (int k = sum5; k >= c_5[i]; k--) {
dp[j][k] = min(dp[j][k], (short int)(dp[j - c_2[i]][k - c_5[i]] + 1));
if (dp[j][k] <= t) ans = max(ans, min(j, k));
}
}
cout << ans << endl;
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 210;
const int max_n = 210;
const int max_size2 = 205 * 64;
const int max_size5 = 205 * 35;
short int c_5[max_n], c_2[max_n];
short int dp[max_size2][max_size5];
int main() {
int n, t;
cin >> n >> t;
int sum2 = 0;
int sum5 = 0;
for (int i = 0; i < n; i++) {
long long a;
cin >> a;
long long tmp = a;
while (tmp % 2 == 0) c_2[i]++, tmp /= 2;
tmp = a;
while (tmp % 5 == 0) c_5[i]++, tmp /= 5;
}
for (int i = 0; i < max_size2; i++)
for (int j = 0; j < max_size5; j++) dp[i][j] = inf;
dp[0][0] = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
sum2 += c_2[i];
sum5 += c_5[i];
for (int j = sum2; j >= c_2[i]; j--)
for (int k = sum5; k >= c_5[i]; k--) {
dp[j][k] = min(dp[j][k], (short int)(dp[j - c_2[i]][k - c_5[i]] + 1));
if (dp[j][k] <= t) ans = max(ans, min(j, k));
}
}
cout << ans << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
int f[2][MAXN][6005], sum2[MAXN], sum5[MAXN];
int main() {
int N, K;
scanf("%d%d", &N, &K);
for (int i = 1; i <= N; i++) {
long long x;
cin >> x;
while ((x & 1) == 0) {
sum2[i]++;
x >>= 1;
}
while (x % 5 == 0) {
sum5[i]++;
x /= 5;
}
}
memset(f, -1, sizeof(f));
f[0][0][0] = 0;
for (int i = 1; i <= N; i++)
for (int j = 0; j <= K; j++)
for (int k = 0; k <= 6000; k++) {
f[i % 2][j][k] = f[(i - 1) % 2][j][k];
if (j >= 1 && k >= sum5[i] && f[(i + 1) % 2][j - 1][k - sum5[i]] != -1)
f[i % 2][j][k] =
max(f[i % 2][j][k], f[(i - 1) % 2][j - 1][k - sum5[i]] + sum2[i]);
}
int ans = 0;
for (int k = 0; k < 6000; k++) ans = max(ans, min(k, f[N % 2][K][k]));
printf("%d", ans);
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
int f[2][MAXN][6005], sum2[MAXN], sum5[MAXN];
int main() {
int N, K;
scanf("%d%d", &N, &K);
for (int i = 1; i <= N; i++) {
long long x;
cin >> x;
while ((x & 1) == 0) {
sum2[i]++;
x >>= 1;
}
while (x % 5 == 0) {
sum5[i]++;
x /= 5;
}
}
memset(f, -1, sizeof(f));
f[0][0][0] = 0;
for (int i = 1; i <= N; i++)
for (int j = 0; j <= K; j++)
for (int k = 0; k <= 6000; k++) {
f[i % 2][j][k] = f[(i - 1) % 2][j][k];
if (j >= 1 && k >= sum5[i] && f[(i + 1) % 2][j - 1][k - sum5[i]] != -1)
f[i % 2][j][k] =
max(f[i % 2][j][k], f[(i - 1) % 2][j - 1][k - sum5[i]] + sum2[i]);
}
int ans = 0;
for (int k = 0; k < 6000; k++) ans = max(ans, min(k, f[N % 2][K][k]));
printf("%d", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
const int N = 256;
vector<pii> fst[N], snd[N], mrg[N];
int n, k, ant;
void merj(int lvl) {
int i, j, la, lb, mxh;
mxh = -1;
la = fst[lvl].size();
lb = snd[lvl].size();
for (i = la - 1, j = lb - 1; i >= 0 && j >= 0;) {
if (fst[lvl][i] > snd[lvl][j]) {
if (fst[lvl][i].second > mxh) {
mrg[lvl].push_back(fst[lvl][i]);
mxh = fst[lvl][i].second;
}
--i;
} else {
if (snd[lvl][j].second > mxh) {
mrg[lvl].push_back(snd[lvl][j]);
mxh = snd[lvl][j].second;
}
--j;
}
}
for (; i >= 0; --i)
if (fst[lvl][i].second > mxh) {
mrg[lvl].push_back(fst[lvl][i]);
mxh = fst[lvl][i].second;
}
for (; j >= 0; --j)
if (snd[lvl][j].second > mxh) {
mrg[lvl].push_back(snd[lvl][j]);
mxh = snd[lvl][j].second;
}
reverse(begin(mrg[lvl]), end(mrg[lvl]));
fst[lvl] = mrg[lvl];
snd[lvl].clear();
mrg[lvl].clear();
}
void apply(int a, int b) {
for (int lvl = 0; lvl < k; ++lvl)
for (auto i : fst[lvl])
snd[lvl + 1].emplace_back(i.first + a, i.second + b);
for (int lvl = 1; lvl <= k; ++lvl) merj(lvl);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
i64 t;
int a, b;
fst[0].emplace_back(0, 0);
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> t;
a = b = 0;
while (t % 2 == 0) {
++a;
t /= 2;
}
while (t % 5 == 0) {
++b;
t /= 5;
}
apply(a, b);
}
for (auto i : fst[k]) ant = max(ant, min(i.first, i.second));
cout << ant << endl;
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
const int N = 256;
vector<pii> fst[N], snd[N], mrg[N];
int n, k, ant;
void merj(int lvl) {
int i, j, la, lb, mxh;
mxh = -1;
la = fst[lvl].size();
lb = snd[lvl].size();
for (i = la - 1, j = lb - 1; i >= 0 && j >= 0;) {
if (fst[lvl][i] > snd[lvl][j]) {
if (fst[lvl][i].second > mxh) {
mrg[lvl].push_back(fst[lvl][i]);
mxh = fst[lvl][i].second;
}
--i;
} else {
if (snd[lvl][j].second > mxh) {
mrg[lvl].push_back(snd[lvl][j]);
mxh = snd[lvl][j].second;
}
--j;
}
}
for (; i >= 0; --i)
if (fst[lvl][i].second > mxh) {
mrg[lvl].push_back(fst[lvl][i]);
mxh = fst[lvl][i].second;
}
for (; j >= 0; --j)
if (snd[lvl][j].second > mxh) {
mrg[lvl].push_back(snd[lvl][j]);
mxh = snd[lvl][j].second;
}
reverse(begin(mrg[lvl]), end(mrg[lvl]));
fst[lvl] = mrg[lvl];
snd[lvl].clear();
mrg[lvl].clear();
}
void apply(int a, int b) {
for (int lvl = 0; lvl < k; ++lvl)
for (auto i : fst[lvl])
snd[lvl + 1].emplace_back(i.first + a, i.second + b);
for (int lvl = 1; lvl <= k; ++lvl) merj(lvl);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
i64 t;
int a, b;
fst[0].emplace_back(0, 0);
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> t;
a = b = 0;
while (t % 2 == 0) {
++a;
t /= 2;
}
while (t % 5 == 0) {
++b;
t /= 5;
}
apply(a, b);
}
for (auto i : fst[k]) ant = max(ant, min(i.first, i.second));
cout << ant << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long INFll = 1ll * 1000000100 * 1000000100;
const long double PI =
3.141592653589793238462643383279502884197169399375105820974944;
int main() {
int n, K;
cin >> n >> K;
vector<int> two(n + 1, 0), five(n + 1, 0);
for (int i = 1; i <= n; i++) {
long long x;
cin >> x;
while (x % 2 == 0) {
two[i]++;
x /= 2;
}
while (x % 5 == 0) {
five[i]++;
x /= 5;
}
}
int dp[2][K + 1][5300];
for (int i = 0; i <= 1; i++)
for (int j = 0; j <= K; j++)
for (int k = 0; k < 5300; k++) dp[i][j][k] = -1000000100;
dp[0][0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= K; j++)
for (int k = 0; k < 5300; k++) {
dp[1][j][k] = dp[0][j][k];
if (k >= five[i] && j > 0)
dp[1][j][k] = max(dp[1][j][k], dp[0][j - 1][k - five[i]] + two[i]);
}
for (int j = 0; j <= K; j++)
for (int k = 0; k < 5300; k++) {
dp[0][j][k] = dp[1][j][k];
dp[1][j][k] = -1000000100;
}
}
int ans = 0;
for (int i = 0; i < 5300; i++) {
int temp = min(i, dp[0][K][i]);
if (ans < temp) ans = temp;
}
cout << ans;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INFll = 1ll * 1000000100 * 1000000100;
const long double PI =
3.141592653589793238462643383279502884197169399375105820974944;
int main() {
int n, K;
cin >> n >> K;
vector<int> two(n + 1, 0), five(n + 1, 0);
for (int i = 1; i <= n; i++) {
long long x;
cin >> x;
while (x % 2 == 0) {
two[i]++;
x /= 2;
}
while (x % 5 == 0) {
five[i]++;
x /= 5;
}
}
int dp[2][K + 1][5300];
for (int i = 0; i <= 1; i++)
for (int j = 0; j <= K; j++)
for (int k = 0; k < 5300; k++) dp[i][j][k] = -1000000100;
dp[0][0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= K; j++)
for (int k = 0; k < 5300; k++) {
dp[1][j][k] = dp[0][j][k];
if (k >= five[i] && j > 0)
dp[1][j][k] = max(dp[1][j][k], dp[0][j - 1][k - five[i]] + two[i]);
}
for (int j = 0; j <= K; j++)
for (int k = 0; k < 5300; k++) {
dp[0][j][k] = dp[1][j][k];
dp[1][j][k] = -1000000100;
}
}
int ans = 0;
for (int i = 0; i < 5300; i++) {
int temp = min(i, dp[0][K][i]);
if (ans < temp) ans = temp;
}
cout << ans;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 102;
const long long MOD = 1000000007;
int N, K, a[202], b[202], F[202][5002], Res;
int main() {
cin >> N >> K;
memset(F, -1, sizeof(F));
for (int i = 1; i <= N; i++) {
long long tmp, x;
cin >> x;
tmp = x;
while (tmp % 2 == 0 && tmp) a[i]++, tmp /= 2;
tmp = x;
while (tmp % 5 == 0 && tmp) b[i]++, tmp /= 5;
}
F[0][0] = 0;
for (int i = 1; i <= N; i++) {
for (int k = K; k >= 1; k--) {
for (int j = 0; j <= 5000; j++)
if (j >= b[i] && F[k - 1][j - b[i]] != -1) {
F[k][j] = max(F[k][j], F[k - 1][j - b[i]] + a[i]);
}
}
}
for (int j = 1; j <= 5000; j++) Res = max(Res, min(j, F[K][j]));
cout << Res;
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 102;
const long long MOD = 1000000007;
int N, K, a[202], b[202], F[202][5002], Res;
int main() {
cin >> N >> K;
memset(F, -1, sizeof(F));
for (int i = 1; i <= N; i++) {
long long tmp, x;
cin >> x;
tmp = x;
while (tmp % 2 == 0 && tmp) a[i]++, tmp /= 2;
tmp = x;
while (tmp % 5 == 0 && tmp) b[i]++, tmp /= 5;
}
F[0][0] = 0;
for (int i = 1; i <= N; i++) {
for (int k = K; k >= 1; k--) {
for (int j = 0; j <= 5000; j++)
if (j >= b[i] && F[k - 1][j - b[i]] != -1) {
F[k][j] = max(F[k][j], F[k - 1][j - b[i]] + a[i]);
}
}
}
for (int j = 1; j <= 5000; j++) Res = max(Res, min(j, F[K][j]));
cout << Res;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 201, M = 25, T = N * M;
int dp[2][N][T];
int two[N], five[N];
void solve() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; ++i) {
long long x;
scanf("%lld", &x);
while (x % 2 == 0) {
two[i]++;
x /= 2;
}
while (x % 5 == 0) {
five[i]++;
x /= 5;
}
}
int maxi = 0;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j <= k; ++j) {
for (int z = 0; z < T; ++z) {
dp[i][j][z] = -1e9;
}
}
}
dp[0][0][0] = 0;
int pos = 0;
for (int i = 0; i < n; ++i) {
int u = min(i, k);
int npos = pos ^ 1;
int v = min(maxi + 30, T);
for (int j = 0; j <= u + 1; ++j) {
for (int z = 0; z < v; ++z) {
dp[npos][j][z] = -1e9;
}
}
int tmp = maxi;
for (int j = 0; j <= u; ++j) {
for (int z = maxi; z >= 0; --z) {
dp[npos][j + 1][z + five[i]] =
max(dp[npos][j + 1][z + five[i]], dp[pos][j][z] + two[i]);
dp[npos][j][z] = max(dp[npos][j][z], dp[pos][j][z]);
if (dp[npos][j + 1][z + five[i]] >= 0) {
tmp = max(tmp, z + five[i]);
}
}
}
maxi = tmp;
pos = npos;
}
int ret = 0;
for (int i = 0; i < T; ++i) {
int u = min(i, dp[pos][k][i]);
if (dp[pos][k][i] >= 0) {
}
ret = max(ret, u);
}
printf("%d\n", ret);
}
int main() { solve(); }
| ### Prompt
Please provide a cpp coded solution to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 201, M = 25, T = N * M;
int dp[2][N][T];
int two[N], five[N];
void solve() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; ++i) {
long long x;
scanf("%lld", &x);
while (x % 2 == 0) {
two[i]++;
x /= 2;
}
while (x % 5 == 0) {
five[i]++;
x /= 5;
}
}
int maxi = 0;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j <= k; ++j) {
for (int z = 0; z < T; ++z) {
dp[i][j][z] = -1e9;
}
}
}
dp[0][0][0] = 0;
int pos = 0;
for (int i = 0; i < n; ++i) {
int u = min(i, k);
int npos = pos ^ 1;
int v = min(maxi + 30, T);
for (int j = 0; j <= u + 1; ++j) {
for (int z = 0; z < v; ++z) {
dp[npos][j][z] = -1e9;
}
}
int tmp = maxi;
for (int j = 0; j <= u; ++j) {
for (int z = maxi; z >= 0; --z) {
dp[npos][j + 1][z + five[i]] =
max(dp[npos][j + 1][z + five[i]], dp[pos][j][z] + two[i]);
dp[npos][j][z] = max(dp[npos][j][z], dp[pos][j][z]);
if (dp[npos][j + 1][z + five[i]] >= 0) {
tmp = max(tmp, z + five[i]);
}
}
}
maxi = tmp;
pos = npos;
}
int ret = 0;
for (int i = 0; i < T; ++i) {
int u = min(i, dp[pos][k][i]);
if (dp[pos][k][i] >= 0) {
}
ret = max(ret, u);
}
printf("%d\n", ret);
}
int main() { solve(); }
``` |
#include <bits/stdc++.h>
using namespace std;
ifstream in("cf.in");
ofstream out("cf.out");
const int DIM = 1e2 + 5;
int dp[205][5205];
int main(void) {
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int n, k;
cin >> n >> k;
memset(dp, -0x3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
long long x;
int c2 = 0, c5 = 0;
cin >> x;
while (x % 2 == 0) {
x /= 2;
++c2;
}
while (x % 5 == 0) {
x /= 5;
++c5;
}
for (int i = k; i >= 1; --i)
for (int j = c5; j < 5200; ++j)
dp[i][j] = max(dp[i][j], dp[i - 1][j - c5] + c2);
}
int ans = 0;
for (int j = 1; j <= 5200; ++j) ans = max(ans, min(j, dp[k][j]));
cout << ans;
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
ifstream in("cf.in");
ofstream out("cf.out");
const int DIM = 1e2 + 5;
int dp[205][5205];
int main(void) {
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int n, k;
cin >> n >> k;
memset(dp, -0x3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
long long x;
int c2 = 0, c5 = 0;
cin >> x;
while (x % 2 == 0) {
x /= 2;
++c2;
}
while (x % 5 == 0) {
x /= 5;
++c5;
}
for (int i = k; i >= 1; --i)
for (int j = c5; j < 5200; ++j)
dp[i][j] = max(dp[i][j], dp[i - 1][j - c5] + c2);
}
int ans = 0;
for (int j = 1; j <= 5200; ++j) ans = max(ans, min(j, dp[k][j]));
cout << ans;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 5;
int main() {
cin.tie(0), cin.sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<long long> v(n);
for (long long &i : v) cin >> i;
vector<int> two(n), five(n);
for (int i = 0; i < n; i++) {
long long x = v[i];
while (x % 2 == 0) {
two[i]++;
x /= 2;
}
while (x % 5 == 0) {
five[i]++;
x /= 5;
}
}
const int MAXLOG = 26;
int maxFives = MAXLOG * n;
vector<vector<int> > prev(k + 1, vector<int>(maxFives, -1));
int ans = 0;
prev[0][0] = 0;
for (int i = n - 1; i >= 0; i--) {
vector<vector<int> > curr = prev;
for (int j = 0; j <= min(k, n - i); j++) {
for (int f = 0; f < maxFives; f++)
if (prev[j][f] != -1) curr[j][f] = prev[j][f];
if (j)
for (int f = five[i]; f < maxFives; f++) {
if (prev[j - 1][f - five[i]] != -1) {
curr[j][f] = max(curr[j][f], two[i] + prev[j - 1][f - five[i]]);
ans = max(ans, min(f, curr[j][f]));
}
}
}
swap(prev, curr);
}
cout << ans;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 5;
int main() {
cin.tie(0), cin.sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<long long> v(n);
for (long long &i : v) cin >> i;
vector<int> two(n), five(n);
for (int i = 0; i < n; i++) {
long long x = v[i];
while (x % 2 == 0) {
two[i]++;
x /= 2;
}
while (x % 5 == 0) {
five[i]++;
x /= 5;
}
}
const int MAXLOG = 26;
int maxFives = MAXLOG * n;
vector<vector<int> > prev(k + 1, vector<int>(maxFives, -1));
int ans = 0;
prev[0][0] = 0;
for (int i = n - 1; i >= 0; i--) {
vector<vector<int> > curr = prev;
for (int j = 0; j <= min(k, n - i); j++) {
for (int f = 0; f < maxFives; f++)
if (prev[j][f] != -1) curr[j][f] = prev[j][f];
if (j)
for (int f = five[i]; f < maxFives; f++) {
if (prev[j - 1][f - five[i]] != -1) {
curr[j][f] = max(curr[j][f], two[i] + prev[j - 1][f - five[i]]);
ans = max(ans, min(f, curr[j][f]));
}
}
}
swap(prev, curr);
}
cout << ans;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int dp[205][15010];
long long a[205];
int s2(long long x) {
int num = 0;
while (x % 2 == 0) {
num++;
x /= 2;
}
return num;
}
int s5(long long x) {
int num = 0;
while (x % 5 == 0) {
num++;
x /= 5;
}
return num;
}
int main() {
int n, k, ans = 0;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
memset(dp, -0x3f3f3f3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
int sum2 = s2(a[i]), sum5 = s5(a[i]);
for (int j = k; j >= 1; j--)
for (int l = sum2; l <= 15000; l++)
dp[j][l] = max(dp[j][l], dp[j - 1][l - sum2] + sum5);
}
for (int i = 0; i <= 15000; i++) ans = max(ans, min(dp[k][i], i));
printf("%d\n", ans);
return 0;
}
| ### Prompt
In cpp, your task is to solve the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[205][15010];
long long a[205];
int s2(long long x) {
int num = 0;
while (x % 2 == 0) {
num++;
x /= 2;
}
return num;
}
int s5(long long x) {
int num = 0;
while (x % 5 == 0) {
num++;
x /= 5;
}
return num;
}
int main() {
int n, k, ans = 0;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
memset(dp, -0x3f3f3f3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
int sum2 = s2(a[i]), sum5 = s5(a[i]);
for (int j = k; j >= 1; j--)
for (int l = sum2; l <= 15000; l++)
dp[j][l] = max(dp[j][l], dp[j - 1][l - sum2] + sum5);
}
for (int i = 0; i <= 15000; i++) ans = max(ans, min(dp[k][i], i));
printf("%d\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
long long get() {
long long x = 0;
char s = getchar();
while (s < '0' || s > '9') s = getchar();
while (s >= '0' && s <= '9')
x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
return x;
}
long long Max(const long long x, const long long y) {
if (x > y) return x;
return y;
}
long long Min(const long long x, const long long y) {
if (x < y) return x;
return y;
}
long long a[205], b[205], dp[205][10005], n, m, ans;
signed main() {
memset(dp, -1, sizeof dp);
dp[0][0] = 0;
n = get(), m = get();
for (long long i = 1, t; i <= n; ++i) {
t = get();
while (t % 2 == 0) t >>= 1, ++a[i];
while (t % 5 == 0) t /= 5, ++b[i];
}
for (long long i = 1; i <= n; ++i)
for (long long j = m; j >= 0; --j)
for (long long k = 10000; k >= 0; --k)
if (j && k >= b[i] && ~dp[j - 1][k - b[i]])
dp[j][k] = Max(dp[j][k], dp[j - 1][k - b[i]] + a[i]);
for (long long i = 0; i <= 10000; ++i) ans = Max(ans, Min(i, dp[m][i]));
printf("%lld", ans);
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
long long get() {
long long x = 0;
char s = getchar();
while (s < '0' || s > '9') s = getchar();
while (s >= '0' && s <= '9')
x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
return x;
}
long long Max(const long long x, const long long y) {
if (x > y) return x;
return y;
}
long long Min(const long long x, const long long y) {
if (x < y) return x;
return y;
}
long long a[205], b[205], dp[205][10005], n, m, ans;
signed main() {
memset(dp, -1, sizeof dp);
dp[0][0] = 0;
n = get(), m = get();
for (long long i = 1, t; i <= n; ++i) {
t = get();
while (t % 2 == 0) t >>= 1, ++a[i];
while (t % 5 == 0) t /= 5, ++b[i];
}
for (long long i = 1; i <= n; ++i)
for (long long j = m; j >= 0; --j)
for (long long k = 10000; k >= 0; --k)
if (j && k >= b[i] && ~dp[j - 1][k - b[i]])
dp[j][k] = Max(dp[j][k], dp[j - 1][k - b[i]] + a[i]);
for (long long i = 0; i <= 10000; ++i) ans = Max(ans, Min(i, dp[m][i]));
printf("%lld", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\n";
err(++it, args...);
}
const double PI = acos(-1);
const double eps = (1e-9);
const long long int INF = (1e18);
const int M = (1e9) + 7;
const int N = 203;
const int K = 5250;
int dp[N][K];
int ar[N][K];
void solve() {
int n, r, i, j, k, a, b;
scanf("%d%d", &n, &r);
vector<pair<int, int> > vp;
long long int x;
for (i = 0; i < n; ++i) {
cin >> x;
a = 0, b = 0;
while (x % 2 == 0) x /= 2, a++;
while (x % 5 == 0) x /= 5, b++;
vp.emplace_back(a, b);
}
for (i = 0; i < N; ++i) {
for (j = 0; j < K; ++j) dp[i][j] = -1, ar[i][j] = -1;
}
dp[0][0] = 0, ar[0][0] = 0;
for (i = 0; i < n; ++i) {
tie(a, b) = vp[i];
for (j = 0; j < i + 1; ++j) {
for (k = 0; k < K - b; ++k) {
if (dp[j][k] >= 0)
ar[j + 1][k + b] = max(ar[j + 1][k + b], dp[j][k] + a);
}
}
for (j = 0; j < N; ++j) {
for (k = 0; k < K; ++k) dp[j][k] = max(dp[j][k], ar[j][k]);
}
}
k = 0;
for (j = 0; j < K; ++j) {
if (dp[r][j] >= 0) k = max(k, min(j, dp[r][j]));
}
printf("%d\n", k);
}
int main() {
int t;
t = 1;
while (t--) solve();
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\n";
err(++it, args...);
}
const double PI = acos(-1);
const double eps = (1e-9);
const long long int INF = (1e18);
const int M = (1e9) + 7;
const int N = 203;
const int K = 5250;
int dp[N][K];
int ar[N][K];
void solve() {
int n, r, i, j, k, a, b;
scanf("%d%d", &n, &r);
vector<pair<int, int> > vp;
long long int x;
for (i = 0; i < n; ++i) {
cin >> x;
a = 0, b = 0;
while (x % 2 == 0) x /= 2, a++;
while (x % 5 == 0) x /= 5, b++;
vp.emplace_back(a, b);
}
for (i = 0; i < N; ++i) {
for (j = 0; j < K; ++j) dp[i][j] = -1, ar[i][j] = -1;
}
dp[0][0] = 0, ar[0][0] = 0;
for (i = 0; i < n; ++i) {
tie(a, b) = vp[i];
for (j = 0; j < i + 1; ++j) {
for (k = 0; k < K - b; ++k) {
if (dp[j][k] >= 0)
ar[j + 1][k + b] = max(ar[j + 1][k + b], dp[j][k] + a);
}
}
for (j = 0; j < N; ++j) {
for (k = 0; k < K; ++k) dp[j][k] = max(dp[j][k], ar[j][k]);
}
}
k = 0;
for (j = 0; j < K; ++j) {
if (dp[r][j] >= 0) k = max(k, min(j, dp[r][j]));
}
printf("%d\n", k);
}
int main() {
int t;
t = 1;
while (t--) solve();
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x7ffffff;
int x[220], y[220];
long long a, ans, f[220][6000];
int main() {
int n, m, sum = 0;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%lld", &a);
long long now = a;
while (now % 5 == 0) {
x[i]++;
now /= 5;
}
sum += x[i];
now = a;
while (now % 2 == 0) {
y[i]++;
now >>= 1;
}
}
for (int k = 0; k <= m; k++)
for (int j = 0; j < 5200; j++) f[k][j] = -INF;
f[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int k = m; k > 0; k--)
for (int j = x[i]; j <= sum; j++)
f[k][j] = max(f[k][j], f[k - 1][j - x[i]] + y[i]);
}
for (int j = 0; j <= sum; j++) {
long long now = f[m][j];
if (j < now) now = j;
ans = max(now, ans);
}
printf("%lld\n", ans);
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x7ffffff;
int x[220], y[220];
long long a, ans, f[220][6000];
int main() {
int n, m, sum = 0;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%lld", &a);
long long now = a;
while (now % 5 == 0) {
x[i]++;
now /= 5;
}
sum += x[i];
now = a;
while (now % 2 == 0) {
y[i]++;
now >>= 1;
}
}
for (int k = 0; k <= m; k++)
for (int j = 0; j < 5200; j++) f[k][j] = -INF;
f[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int k = m; k > 0; k--)
for (int j = x[i]; j <= sum; j++)
f[k][j] = max(f[k][j], f[k - 1][j - x[i]] + y[i]);
}
for (int j = 0; j <= sum; j++) {
long long now = f[m][j];
if (j < now) now = j;
ans = max(now, ans);
}
printf("%lld\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 200;
long long ara[N + 5];
int two[N + 5], five[N + 5];
int n, k;
int dp[2][N + 2][N * 26];
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> ara[i];
for (int i = 1; i <= n; i++) {
while (ara[i] % 2 == 0) {
ara[i] /= 2;
two[i]++;
}
while (ara[i] % 5 == 0) {
ara[i] /= 5;
five[i]++;
}
}
for (int i = 0; i <= k; i++) {
for (int j = 0; j < N * 26; j++) {
if (i == 0 and j == 0)
dp[(n + 1) & 1][i][j] = 0;
else
dp[(n + 1) & 1][i][j] = -1e5;
}
}
for (int i = n; i >= 1; i--) {
for (int j = 0; j <= k; j++) {
for (int l = 0; l < N * 26; l++) {
dp[i & 1][j][l] = dp[(i + 1) & 1][j][l];
if (j > 0 and l - five[i] >= 0)
dp[i & 1][j][l] = max(dp[i & 1][j][l],
two[i] + dp[(i + 1) & 1][j - 1][l - five[i]]);
}
}
}
int ans = 0;
for (int i = 1; i < N * 26; i++) ans = max(ans, min(i, dp[1][k][i]));
cout << ans;
}
| ### Prompt
Please create a solution in cpp to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 200;
long long ara[N + 5];
int two[N + 5], five[N + 5];
int n, k;
int dp[2][N + 2][N * 26];
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> ara[i];
for (int i = 1; i <= n; i++) {
while (ara[i] % 2 == 0) {
ara[i] /= 2;
two[i]++;
}
while (ara[i] % 5 == 0) {
ara[i] /= 5;
five[i]++;
}
}
for (int i = 0; i <= k; i++) {
for (int j = 0; j < N * 26; j++) {
if (i == 0 and j == 0)
dp[(n + 1) & 1][i][j] = 0;
else
dp[(n + 1) & 1][i][j] = -1e5;
}
}
for (int i = n; i >= 1; i--) {
for (int j = 0; j <= k; j++) {
for (int l = 0; l < N * 26; l++) {
dp[i & 1][j][l] = dp[(i + 1) & 1][j][l];
if (j > 0 and l - five[i] >= 0)
dp[i & 1][j][l] = max(dp[i & 1][j][l],
two[i] + dp[(i + 1) & 1][j - 1][l - five[i]]);
}
}
}
int ans = 0;
for (int i = 1; i < N * 26; i++) ans = max(ans, min(i, dp[1][k][i]));
cout << ans;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a5[220], a2[220];
int dp[220][6000];
int main() {
while (cin >> n >> k) {
memset(a5, 0, sizeof(a5));
memset(a2, 0, sizeof(a2));
int sum = 0;
for (int i = 1; i <= n; i++) {
long long x;
cin >> x;
while (x % 2 == 0) {
x /= 2;
a2[i]++;
}
while (x % 5 == 0) {
x /= 5;
a5[i]++;
}
sum += a5[i];
}
memset(dp, -0x3f3f3f3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j >= 1; j--) {
for (int p = a5[i]; p <= sum; p++) {
dp[j][p] = max(dp[j][p], dp[j - 1][p - a5[i]] + a2[i]);
}
}
}
int ans = 0;
for (int i = 1; i <= sum; i++) {
ans = max(ans, min(dp[k][i], i));
}
cout << ans << endl;
}
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
Input
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Output
Print maximal roundness of product of the chosen subset of length k.
Examples
Input
3 2
50 4 20
Output
3
Input
5 3
15 16 3 25 9
Output
3
Input
3 3
9 77 13
Output
0
Note
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a5[220], a2[220];
int dp[220][6000];
int main() {
while (cin >> n >> k) {
memset(a5, 0, sizeof(a5));
memset(a2, 0, sizeof(a2));
int sum = 0;
for (int i = 1; i <= n; i++) {
long long x;
cin >> x;
while (x % 2 == 0) {
x /= 2;
a2[i]++;
}
while (x % 5 == 0) {
x /= 5;
a5[i]++;
}
sum += a5[i];
}
memset(dp, -0x3f3f3f3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j >= 1; j--) {
for (int p = a5[i]; p <= sum; p++) {
dp[j][p] = max(dp[j][p], dp[j - 1][p - a5[i]] + a2[i]);
}
}
}
int ans = 0;
for (int i = 1; i <= sum; i++) {
ans = max(ans, min(dp[k][i], i));
}
cout << ans << endl;
}
}
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.