Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- using namespace std;
- const int mx=1e3+123;
- int v[mx];
- int main()
- {
- optimize();
- int n;
- cin>>n;
- for(int i=0;i<n;i++)
- {
- cin>>v[i];
- }
- int j=1,s=0,d=0,l=0,r=n-1;
- while(l<=r)
- {
- if(j==1)
- {
- if(v[l]>v[r])
- {
- s+=v[l];
- l++;
- }
- else
- {
- s+=v[r];
- r--;
- }
- j=2;
- }
- else if(j==2)
- {
- if(v[l]>v[r])
- {
- d+=v[l];
- l++;
- }
- else
- {
- d+=v[r];
- r--;
- }
- j=1;
- }
- }
- cout<<s<<" "<<d;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement