Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. int main() {
  7. ifstream in("input.txt");
  8. ofstream out("output.txt");
  9. int n = 0;
  10. in >> n;
  11. if (n > 0) {
  12. int *array = new int[n];
  13. int *res_array = new int[n];
  14. for (int i = 0; i < n; i++) {
  15. res_array[i] = -1;
  16. in>>array[i];
  17. }
  18. res_array[0] = array[0];
  19. res_array[2] = array[2] + array[0];
  20. for (int i = 3; i < n; i++) {
  21. res_array[i] = fmax(res_array[i - 3], res_array[i - 2]) + array[i];
  22. }
  23. out << res_array[n - 1];
  24. }
  25. else {
  26. out << -1;
  27. }
  28. system("pause");
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement