Advertisement
momo2345

sereja and dima

Jul 11th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.   int n;
  5.   cin>>n;
  6.   vector<int>v(n);
  7.   for(int i=0;i<n;i++) cin>>v[i];
  8.   int s=0,d=0,f=1;
  9.   while(!v.empty()){
  10.     if(f&1){
  11.         if(*v.begin()>v.back()) {s+=*v.begin(); v.erase(v.begin());}
  12.         else {s+=v.back(); v.pop_back();}
  13.         f++;
  14.     }
  15.     else{
  16.              if(*v.begin()>v.back()) {d+=*v.begin(); v.erase(v.begin());}
  17.         else {d+=v.back(); v.pop_back();}
  18.         f++;
  19.     }
  20.  
  21.   }
  22.    cout<<s<<" "<<d<<endl;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement