Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n,first = 0,st,f,a[101],moves,even,odd;
  4. bool odds;
  5. void getmove(bool c) {
  6. if (odds) {
  7. if (st % 2 == 1) {
  8. if (c)first += a[st];
  9. st++;
  10. }
  11. else {
  12. if (c)first += a[f];
  13. f--;
  14. }
  15. }
  16. else {
  17. if (st % 2 == 1) {
  18. if (c)first += a[f];
  19. f--;
  20. }
  21. else {
  22. if (c)first += a[st];
  23. st++;
  24. }
  25. }
  26. }
  27. int main() {
  28. cin>>n;
  29. for (int i = 1;i<=n;i++) {
  30. scanf("%d",&a[i]);
  31. if (i % 2 == 0)even += a[i];
  32. else odd += a[i];
  33. }
  34. if (odd >= even)odds = true;
  35. else odds = false;
  36. moves = n/2;
  37. st = 1;
  38. f = n;
  39. for (int i = 1;i<=moves;i++) {
  40. getmove(true);
  41. getmove(false);
  42. }
  43. cout<<first<<" "<<even+odd-first<<endl;
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement