Created
May 28, 2015 17:27
-
-
Save sukeesh/c84cb8447a21fdee381c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//HOTELS - Hotels Along the Croatian Coast | |
/* | |
Author | |
-Sukeesh | |
*/ | |
#include<iostream> | |
#include<cstdio> | |
#include<limits.h> | |
using namespace std; | |
int main(){ | |
long n,m; | |
scanf("%ld%ld",&n,&m); | |
long a[n],i; | |
for(i=0;i<n;i++) | |
{ | |
scanf("%ld", &a[i]); | |
} | |
long cur=0,j=0,sum=0; | |
for(i=0;i<n;i++) | |
{ | |
if(cur+a[i]<m) | |
{ | |
cur+=a[i]; | |
} | |
else if(cur+a[i]==m) | |
{ | |
cout<<m; | |
return 0; | |
} | |
else | |
{ | |
while(cur+a[i]>m) | |
{ | |
cur-=a[j]; | |
j++; | |
} | |
if(cur+a[i]<m) | |
{ | |
cur+=a[i]; | |
} | |
else if(cur+a[i]==m) | |
{ | |
printf("%ld",m); | |
return 0; | |
} | |
} | |
sum=max(sum,cur); | |
} | |
printf("%ld",sum); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment