Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <math.h>
- using namespace std;
- int main() {
- ifstream in("input.txt");
- ofstream out("output.txt");
- int n = 0;
- in >> n;
- if (n > 0) {
- int *array = new int[n];
- int *res_array = new int[n];
- for (int i = 0; i < n; i++) {
- res_array[i] = -1;
- in>>array[i];
- }
- res_array[0] = array[0];
- res_array[2] = array[2] + array[0];
- for (int i = 3; i < n; i++) {
- res_array[i] = fmax(res_array[i - 3], res_array[i - 2]) + array[i];
- }
- out << res_array[n - 1];
- }
- else {
- out << -1;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement