Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- void Input (vector<int>& n) {for (int i = 0; i < n.size(); ++i) cin >> n[i];}
- void Output (vector<int> n) {for (int i = 0; i < n.size(); ++i) cout << n[i] << " ";}
- int main()
- {
- int n = 0; cin >> n;
- vector<int> ingrowth(n,-1), inage(n,-1);
- vector<int>::iterator it1, it2;
- Input(ingrowth); Input(inage);
- vector<int> growth(0), age(0);
- for (int i = 0; i < n; ++i)
- {
- it1 = growth.begin();
- it2 = age.begin();
- growth.insert(it1, ingrowth[i]);
- age.insert(it2, inage[i]);
- for(int i = 0;i<growth.size()-1 && growth[i]>growth[i+1] && age[i+1]-age[i] <= 5;++i)
- {
- swap(growth[i],growth[i+1]);
- swap(age[i],age[i+1]);
- }
- }
- Output(growth);
- return 0;
- }
- /*
- 6
- 160 173 138 145 153 170
- 15 17 12 18 16 12
- ans: 138 170 145 153 160 173
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement