-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmax.cpp
More file actions
51 lines (38 loc) · 973 Bytes
/
max.cpp
File metadata and controls
51 lines (38 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
void printArray(vector<int> arr){
for (int i = 0;i<arr.size();i++){
cout<<arr[i]<<" ";
}
}
int findMaxX(int n, vector<vector<int>> &arr, int B)
{
vector <int> arr1;
for(int i = 0;i<n;i++){
int sum = 0;
for(int j =0;j<arr.size();j++){
sum+=arr[i][j];
}
arr1.push_back(sum);
cout<<"The "<<i<<"pushed is "<<sum<<endl;
}
int ans =0;
cout<<"The answer arrar Elements are : ";
printArray(arr1);
for(int i = 0;i<arr1.size();i++){
if(B>ans){
ans+=arr1[i];
}
else{
break;
}
cout<<"The first answer is :"<<ans<<endl;
}
return ans;
}
int main(){
vector < vector<int> > arr ={{3 ,1, 2, 3},
{3 ,4 ,2, 3},
{3 ,1, 10, 2}};
findMaxX(3,arr,20);
}