-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathmaxsubarray.cpp
More file actions
45 lines (45 loc) · 817 Bytes
/
maxsubarray.cpp
File metadata and controls
45 lines (45 loc) · 817 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
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int counter;
cin>>counter;
while(counter--)
{
int size;
cin>>size;
int arr[size];
for(int i=0;i<size;i++)
{
cin>>arr[i];
cout<<arr[i]<<" ";
}
int i=0;
int z=0;
int ma;
while(true)
{
if(z==size-1)
{
break;
}
if(i==z)
{
ma=max(arr[i],arr[i+1]);
}
else{
ma=max(ma,arr[i+1]);
}
cout<<ma<<" ";
i++;
if(i==size-1)
{
z++;
i=z;
}
}
cout<<endl;
}
return 0;
}