Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- long elementsSum(const std::vector<std::vector<int> >& arr, int d = 0){
- //your code here
- long sum = 0;
- int indice = arr.size() - 1;
- for(int i = 0; i < arr.size(); i++) {
- if(arr[i].size() > 0 && indice >= 0 && indice < arr[i].size()) {
- sum += arr[i][indice];
- }
- else {
- sum += d;
- }
- indice--;
- }
- return sum ;
- }
- int main() {
- std::vector<std::vector<int> > v;
- std::vector<int> aux1;
- aux1.push_back(-5);
- aux1.push_back(-7);
- aux1.push_back(-9);
- std::vector<int> aux2;
- aux2.push_back(-90);
- aux2.push_back(-22);
- aux2.push_back(-10);
- v.push_back(aux1);
- v.push_back(aux2);
- cout << elementsSum(v, 1) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement