Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>;
- using namespace std;
- int main() {
- std::ifstream fin("input.txt");
- std::ofstream fout("output.txt");
- int n;
- fin >> n;
- vector<int> mass;
- int temp;
- for (int i = 0; i < n; i++) {
- fin >> temp;
- mass.push_back(temp);
- }
- mass.push_back(-1000001);
- int left = 0, right = 1, answ = 0;
- for (int i = 1; i < mass.size() - 2; i++) {
- if (mass[i - 1] > mass[left]) {
- left = i - 1;
- }
- if (right <= i) {
- int right_data = -1000001;
- for (int j = i + 1; j < mass.size(); j++) {
- if (right_data <= mass[j] || (mass[j] == -1000001 && right == i)) {
- right = j;
- right_data = mass[right];
- }
- }
- }
- if (mass[left] > mass[i] && mass[right] > mass[i]) {
- mass[i] = -1000001;
- answ++;
- }
- }
- fout << n - answ << endl;
- for (int i = 0; i < mass.size(); i++) {
- if (mass[i] != -1000001) {
- fout << mass[i] << " ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment