SRM Elab Dsa Ans

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

eLab Role: Student Name: Abhinav Id: 307589233604 Dept: Computer Science And Engineering LOGOUT

November 11th 2024, 11:42:30 Pm

CHALLENGE INFORMATION

You have already solved this challenge ! Though you can run the code with different logic !

Course DS Session Hashing Question Information Level 1 Challenge 96

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

Problem Input Format

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

Test Case 1 Test Case 2

INPUT (STDIN) INPUT (STDIN)

4 15
5 -2 7 -3 2 3 4 5 6 7 3 4 2 7 6 8 6 4 9

EXPECTED OUTPUT EXPECTED OUTPUT

17 2021

Mandatory Test Cases

Test Cases
Test Case 1

KEYWORD

int NA[N];

Complexity Test Cases

Test Case 1 Test Case 2 Test Case 3

CYCLOMATIC COMPLEXITY TOKEN COUNT NLOC

3 555 73
Code
You have already solved this challenge ! Though you can run the code with different logic !
Editor

Code Editor c Custom Input (stdin) T1 T2

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

You might also like