Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<int> arr = {1,4,2,5,3};
- int size = arr.size();
- int sum = 0;
- vector<int> prefix(size+1);
- for(int i =1;i<=size;i++)
- {
- prefix[i] = prefix[i-1] + arr[i-1];
- }
- for(int i =1;i<=size;i++)
- {
- for(int j=i;j<=size;j++)
- {
- if(((j-i) + 1) %2 == 1)
- {
- sum += (prefix[j] - prefix[i-1]);
- }
- }
- }
- return sum;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement