From f624eb1c5fbac6215dd169a9c7cd7a673336bfd0 Mon Sep 17 00:00:00 2001 From: Sanya Kumari <1701sanya@gmail.com> Date: Sat, 25 Jul 2020 16:38:03 +0530 Subject: [PATCH] Create RENT.cpp --- Hackerearth/RENT.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Hackerearth/RENT.cpp diff --git a/Hackerearth/RENT.cpp b/Hackerearth/RENT.cpp new file mode 100644 index 0000000..6a49ed7 --- /dev/null +++ b/Hackerearth/RENT.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; +unsigned long long int findMaxSubarraySum(unsigned long long int arr[],unsigned long long int n,unsigned long long int sum) +{ + unsigned long long int curr_sum = arr[0], max_sum = 0, start = 0; + for (unsigned long long int i = 1; i < n; i++) { + if (curr_sum <= sum) + max_sum = max(max_sum, curr_sum); + while (curr_sum + arr[i] > sum && start < i) { + curr_sum -= arr[start]; + start++; + } + curr_sum += arr[i]; + } + if (curr_sum <= sum) + max_sum = max(max_sum, curr_sum); + return max_sum; +} +int main() +{ + unsigned long long int n; + cin>>n; + unsigned long long int x; + cin>>x; + long long int y; + cin>>y; + unsigned long long int max=0; + unsigned long long int sum; + unsigned long long int array[n]; + unsigned long long int arr[n]; + for(unsigned long long int i=0; i> array[i]; + } + while(y--){ + max = max+ findMaxSubarraySum(array, n, x); + x= 2*x; + for (unsigned long long int k=0; k