You are a skier participating in a giant slalom. The slalom track is located on a ski slope, goes downhill and is fenced by barriers on both sides. The barriers are perpendicular to the starting line located at the top of the slope. There are N slalom gates on the track. Each gate is placed at a distinct distance from the starting line and from the barrier on the right-hand side (looking downhill).
You start from any place on the starting line, ski down the track passing as many gates as possible, and finish the slalom at the bottom of the slope. Passing a gate means skiing through the position of the gate.
You can ski downhill in either of two directions: to the left or to the right. When you ski to the left, you pass gates of increasing distances from the right barrier, and when you ski to the right, you pass gates of decreasing distances from the right barrier. You want to ski to the left at the beginning.
Unfortunately, changing direction (left to right or vice versa) is exhausting, so you have decided to change direction at most two times during your ride. Because of this, you have allowed yourself to miss some of the gates on the way down the slope. You would like to know the maximum number of gates that you can pass with at most two changes of direction.
The arrangement of the gates is given as an array A consisting of N integers, whose elements specify the positions of the gates: gate K (for 0 ≤ K < N) is at a distance of K+1 from the starting line, and at a distance of A[K] from the right barrier.
For example, consider array A such that:
A[0] = 15 A[1] = 13 A[2] = 5 A[3] = 7 A[4] = 4 A[5] = 10 A[6] = 12 A[7] = 8 A[8] = 2 A[9] = 11 A[10] = 6 A[11] = 9 A[12] = 3The picture above illustrates the example track with N = 13 gates and a course that passes eight gates. After starting, you ski to the left (from your own perspective). You pass gates 2, 3, 5, 6 and then change direction to the right. After that you pass gates 7, 8 and then change direction to the left. Finally, you pass gates 10, 11 and finish the slalom. There is no possible way of passing more gates using at most two changes of direction.
Write a function:
int solution(vector<int> &A);
that, given an array A consisting of N integers, describing the positions of the gates on the track, returns the maximum number of gates that you can pass during one ski run.
For example, given the above data, the function should return 8, as explained above.
For the following array A consisting of N = 2 elements:
A[0] = 1 A[1] = 5the function should return 2.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- each element of array A is an integer within the range [1..1,000,000,000];
- the elements of A are all distinct.
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &AI) {
/*
The idea is that instead of turns we just reflect symmetrically the field, so the movement after the turn is the moving in the reflection
The axis of reflection is the right barrier for the first turn plus 1 or any posiive number or its mirror image again for the right turn
The only problem that gates cannot be on the same index, so we first triple index and use remainders 0,1,2 to put gates the rightest, the middle and the leftest
This order ensures that we do not return after the turn
*/
const static long long limit = 1000000000 + 1;
int N = AI.size();
vector<long long>AL(3 * N);
for (int i = 0; i < N; i++) {
long long t1 = 3 * (long long)AI.at(i);
long long t2 = 2 * 3 * limit - t1;
long long t3 = 4 * 3 * limit - t2;
AL.at(3 * i + 0) = t3;
AL.at(3 * i + 1) = t2;
AL.at(3 * i + 2) = t1;
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &AI) {
vector<long long>AL = prepareArray(AI);
int res = findLISBetter(AL);
return res;
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
int N = A.size();
vector<long long>AL(3 * N);
for (int i = 0; i < N; i++) {
long long t1 = 3 * (long long)AI.at(i);
long long t2 = 2 * 3 * limit - t1;
long long t3 = 4 * 3 * limit - t2;
AL.at(3 * i + 0) = t3;
AL.at(3 * i + 1) = t2;
AL.at(3 * i + 2) = t1;
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &AI) {
vector<long long>AL = prepareArray(AI);
int res = findLISBetter(AL);
return res;
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
vector<long long>AL;
for (int i = 0; i < N; i++) {
long long t1 = 3 * (long long)AI.at(i);
long long t2 = 2 * 3 * limit - t1;
long long t3 = 4 * 3 * limit - t2;
AL.at(3 * i + 0) = t3;
AL.at(3 * i + 1) = t2;
AL.at(3 * i + 2) = t1;
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &AI) {
vector<long long>AL = prepareArray(AI);
int res = findLISBetter(AL);
return res;
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
vector<long long>AL;
for (int i = 0; i < N; i++) {
AL.push;
AL.at(3 * i + 1) = t2;
AL.at(3 * i + 2) = t1;
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &AI) {
vector<long long>AL = prepareArray(AI);
int res = findLISBetter(AL);
return res;
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
vector<long long> AL;
for (int i = 0; i < N; i++) {
AL.push_back();
AL.at(3 * i + 1) = t2;
AL.at(3 * i + 2) = t1;
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &AI) {
vector<long long>AL = prepareArray(AI);
int res = findLISBetter(AL);
return res;
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
vector<long long> AL;
for (int i = 0; i < N; i++) {
AL.push_back(2 * limit);
AL.at(3 * i + 1) = t2;
AL.at(3 * i + 2) = t1;
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &AI) {
vector<long long>AL = prepareArray(AI);
int res = findLISBetter(AL);
return res;
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
vector<long long> AL;
for (int i = 0; i < N; i++) {
AL.push_back(2 * limit + (long long)i);
AL.at(3 * i + 1) = t2;
AL.at(3 * i + 2) = t1;
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &AI) {
vector<long long>AL = prepareArray(AI);
int res = findLISBetter(AL);
return res;
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * limit + (long long)i);
AL.at(3 * i + 1) = t2;
AL.at(3 * i + 2) = t1;
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &AI) {
vector<long long>AL = prepareArray(AI);
int res = findLISBetter(AL);
return res;
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * limit + (long long)i);
AL.push_back(2 * limit - (long long)i);
AL.push_back(2 * limit + (long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &AI) {
vector<long long>AL = prepareArray(AI);
int res = findLISBetter(AL);
return res;
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * limit + (long long)i);
AL.push_back(2 * limit - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &AI) {
vector<long long>AL = prepareArray(AI);
int res = findLISBetter(AL);
return res;
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * limit + (long long)i);
AL.push_back(2 * limit - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &AI) {
int res = findLISBetter(prepareArray(A));
return res;
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * limit + (long long)i);
AL.push_back(2 * limit - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &AI) {
return findLISBetter(prepareArray(A));
;
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * limit + (long long)i);
AL.push_back(2 * limit - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * limit + (long long)i);
AL.push_back(2 * limit - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
func.cpp: In function 'int findLISBetter(std::vector<long long int>)': func.cpp:20:55: error: 'upper_bound' was not declared in this scope auto po1 = upper_bound(res1.begin(), res1.end(), *au); ^
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
const static long long limit = 1000000000 + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * limit + (long long)i);
AL.push_back(2 * limit - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long limit = 1000000000 + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * limit + (long long)i);
AL.push_back(2 * limit - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * limit + (long long)i);
AL.push_back(2 * limit - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
// binary search using fu
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
// binary search using function from std lib
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1) {
res1.push_back(*au);
}
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
// binary search using function from std lib
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1)
res1.push_back(*au);
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
// binary search using function from std lib
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1)
res1.push_back(*au);//
else
*po1 = *au;
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>AL) {
vector< long long> res1;
for (auto au = AL.begin(); au != AL.end(); au++) {
// binary search using function from std lib
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1)
res1.push_back(*au);// not found
else
*po1 = *au; // found
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> res1;
for (auto au = A.begin(); au != A.end(); au++) {
// binary search using function from std lib
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1)
res1.push_back(*au);// not found
else
*po1 = *au; // found in A
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> res1;
for (auto it = A.begin(); it != A.end(); it++) {
// binary search using function from std lib
auto po1 = upper_bound(res1.begin(), res1.end(), *au);
if (res1.end() == po1)
res1.push_back(*au);// not found
else
*po1 = *au; // found in A
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> res1;
for (auto it = A.begin(); it != A.end(); it++) {
// binary search using function from std lib
auto po1 = upper_bound(res1.begin(), res1.end(), *it);
if (res1.end() == po1)
res1.push_back(*it);// not found
else
*po1 = *it; // found in A
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> res1;
for (auto i) {
// binary search using function from std lib
auto po1 = upper_bound(res1.begin(), res1.end(), *it);
if (res1.end() == po1)
res1.push_back(*it);// not found
else
*po1 = *it; // found in A
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> res1;
for (auto i : A) {
// binary search using function from std lib
auto po1 = upper_bound(res1.begin(), res1.end(), i);
if (res1.end() == po1)
res1.push_back(i);// not found
else
*po1 = i; // found in A
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> res1;
for (auto i : A) {
// binary search using function from std lib
auto po1 = upper_bound(res1.begin(), res1.end(), i);
if (res1.end() == po1)
res1.push_back(i);// not found, extend
else
*po1 = i; // found in A
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> M;
for (auto i : A) {
// binary search using function from std lib
auto po1 = upper_bound(M.begin(), M.end(), i);
if (M.end() == po1)
M.push_back(i);// not found, extend M
else
*po1 = i; // found in A
}
return res1.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> M;
for (auto i : A) {
// binary search using function from std lib
auto po1 = upper_bound(M.begin(), M.end(), i);
if (M.end() == po1)
M.push_back(i);// not found, extend M
else
*po1 = i; // found in A
}
return M.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> M;
for (auto i : A) {
// binary search using function from std lib
auto po1 = upper_bound(M.begin(), M.end(), i);
if (M.end() == po1)
M.push_back(i);// not found, extend M
else
*po1 = i; // found in A, replace
}
return M.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> M;
for (auto i : A) {
// binary search using function from std lib
auto po1 = upper_bound(M.begin(), M.end(), i);
if (M.end() == po1)
M.push_back(i);// not found, extend M
else
*po1 = i; // found in A, replace M[pos]
}
return M.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> M;
for (auto i : A) {
// binary search using function from std lib
auto j = upper_bound(M.begin(), M.end(), i);
if (M.end() == j)
M.push_back(i);// not found, extend M
else
*j = i; // found in A, replace M[j]
}
return M.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> M;
for (auto i : A) {
// binary search using function from std lib
auto j = upper_bound(M.begin(), M.end(), i);
if (M.end() == j)
M.push_back(i);// not found, extend M
else
*j = i; // found in A, replace M[j] = i
}
return M.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> M;
for (auto i : A) {
// binary search using function from std lib
auto j = upper_bound(M.begin(), M.end(), i);
if (M.end() == j)
M.push_back(i);// not found, extend M
else
*j = i; // found in A, replace M[j] = i
}
return M.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
vector<long long> prepareArray(vector<int> &A) {
long long maxA = *(std::max_element(A.begin(), A.end())) + 1;
vector<long long> AL;
for (auto i : A) {
AL.push_back(2 * maxA + (long long)i);
AL.push_back(2 * maxA - (long long)i);
AL.push_back((long long)i);
}
return AL;
}
int findLISBetter(vector<long long>A) {
vector< long long> M;
for (auto i : A) {
// binary search using function from std lib
auto j = upper_bound(M.begin(), M.end(), i);
if (M.end() == j)
M.push_back(i);// not found, extend M
else
*j = i; // found in A, replace M[j] = i
}
return M.size();
}
int solution(vector<int> &A) {
return findLISBetter(prepareArray(A));
}
The solution obtained perfect score.