Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdc1b9b1

Browse files
Disk Space Analysis
Problem Statement -: You are given an array, You have to choose a contiguous subarray of length ‘k’, and find the minimum of that segment, return the maximum of those minimums.Sample input 0 1 → Length of segment x =15 → size of space n = 51 → space = [ 1,2,3,1,2]2 3 1 2 Sample output3ExplanationThe subarrays of size x = 1 are [1],[2],[3],[1], and [2],Because each subarray only contains 1 element, each value is minimal with respect to the subarray it is in. The maximum of these values is 3. Therefore, the answer is 3
1 parent8ba63a5 commitdc1b9b1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎Disk Space Analysis.cpp‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include<bits/stdc++.h>
2+
usingnamespacestd;
3+
vector<int> arr;
4+
int prevmin=-1;
5+
int flag=0;
6+
int x,n,q;
7+
8+
intsorting(int start,int end)
9+
{
10+
if(start+1==n) {start=0;end=end-n;}
11+
if(start==end)return arr[start];
12+
returnmin(arr[start],sorting(start+1,end));
13+
}
14+
15+
intfunc(int start,int end)
16+
{
17+
if(flag==0) {flag++;return prevmin=sorting(start,end);}
18+
if(arr[start-1]==prevmin)return prevmin;
19+
return prevmin=(arr[end]<=prevmin)?prevmin:sorting(start,end);
20+
21+
}
22+
23+
intmain()
24+
{
25+
cin>>x>>n;
26+
int ans=0;
27+
for(int i=0;i<n;i++)
28+
{cin>>q;arr.push_back(q);}
29+
for(int i=0;i<n;i++)
30+
{
31+
ans=max(ans,func(i,i+x-1));
32+
}
33+
cout<<ans;
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp