#include <iostream>
#include <vector>
std::size_t NextList(std::vector<int> vec,std::size_t Start=0){
std::size_t i = Start;
for (i=Start; i < vec.size()-1; i++){
if (vec[i] > vec[i + 1])break;
}
return i;
}
std::vector < std::vector<int>> ToList(const std::vector<int>& vec){
std::vector<std::vector<int>> vecvec;
std::size_t S = 0;
std::size_t E = 0;
while (E < vec.size()){
E = NextList(vec,S);
E++;
vecvec.push_back(std::vector<int>(vec.begin() + S, vec.begin() + E));
S = E;
}
return vecvec;
}
bool Show(std::vector<int>& vec, std::vector < std::vector<int>> & vecvec){
std::cout << '[';
for (auto& o : vec) std::cout << o << ',';
std::cout << ']';
std::cout << " => ";
std::cout << '[';
for (auto& oo : vecvec){
std::cout << '[';
for (auto& o : oo) std::cout << o << ',';
std::cout << ']';
}
std::cout << ']' << std::endl;
return true;
}
int main(){
std::vector<int> vec;
std::vector<std::vector<int>> vecvec;
vec = { 8, 3, 4, 9, 9, 10, 6, 1, 4, 3 };// = > [[8], [3, 4, 9, 9, 10], [6], [1, 4], [3]]
vecvec= ToList(vec);
Show(vec,vecvec);
vec = { 1, 3, 3, 4, 4, 6, 8, 9, 9, 10 };// = > [[1, 3, 3, 4, 4, 6, 8, 9, 9, 10]]
vecvec= ToList(vec);
Show(vec,vecvec);
vec = { 10, 9, 9, 8, 6, 4, 4, 3, 3, 1 };/// = > [[10], [9, 9], [8], [6], [4, 4], [3, 3], [1]]
vecvec= ToList(vec);
Show(vec,vecvec);
vec = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };// = > [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
vecvec= ToList(vec);
Show(vec,vecvec);
vec = {};// = > []
vecvec= ToList(vec);
Show(vec,vecvec);
vec = { 1 };// = > [[1]]
vecvec= ToList(vec);
Show(vec,vecvec);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKc3RkOjpzaXplX3QgTmV4dExpc3Qoc3RkOjp2ZWN0b3I8a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