SRM Elab Dsa Ans
SRM Elab Dsa Ans
SRM Elab Dsa Ans
CHALLENGE INFORMATION
You have already solved this challenge ! Though you can run the code with different logic !
Problem Description
Given an array A of N integers. Now, you have to output the sum of unique values of the maximum subarray sum of all the possible subarrays
of the given array A .
Note: Subarray means contiguous elements with at-least one element in it.
Constraints
1 ≤ N ≤ 2000
9
0 ≤ |Ai | ≤ 10
The first line of the input contains a single integer N , the total number of elements in array A .
The next line of the input contains N space-separated integers representing the elements of the array.
Output Format
The only single line of the output should contain a single integral value representing the answer to the problem.
Logical Test Cases
4 15
5 -2 7 -3 2 3 4 5 6 7 3 4 2 7 6 8 6 4 9
17 2021
Test Cases
Test Case 1
KEYWORD
int NA[N];
3 555 73
Code
You have already solved this challenge ! Though you can run the code with different logic !
Editor
1 #include<bits/stdc++.h>
Type Here
2 using namespace std;
3 //abhinav Vats RA2311003030310
4
5 void solve(){
6 cout<<"int NA[N];"; Output MATCH T1 MATCH T2
7 }
8 int main(){
9 int n;
10 cin>>n;
Empty
11 int a[n];
12 for(int i=0;i<n;i++){
13 cin>>a[i]; Complexity Analysis
14 }
15 unordered_set<long long> s;
16 for(int i = 0 ; i< n; i++){
17 long long sum = 0 , max_sum=INT_MIN; Test Case Status
18 for(int j = i ; j<n ; j++){
19 sum += a[j];
20 max_sum = max(sum, max_sum);
21 if(sum<0){
22 sum = 0;
23 }
24 s.insert(max_sum);
25 }
26 }
27 long long ans = 0;
28 for(auto i:s){
SAVE RESET RUN EVALUATE
Waiting for your Submission !
Your code will be Evaluated
For any inquiries, please contact your Faculty or Course Coordinator Student Manual DOWNLOAD