Murthal paratha problem divide and conquer

#include<bits/stdc++.h>

using namespace std;

int f(int time,int rank){
int c=0,totaltime=0;
while(totaltime<time){
totaltime+=rank*(++c);
}
return c;
}

int main(){
int p; cin>>p;
int s; cin>>s;
int a[s];
for(int i=0;i<s;i++) cin>>a[i];
int h=a[s-1](s(s+1)/2);
int l=0,min=INT_MAX;
while(l<=h){
int mid=(l+h)/2,op=0;
for(int i=0;i<s;i++){
op+=f(mid,a[i]);
}

    if(op>=p){
        min=mid;
        h=mid-1;
    }
    else{
        l=mid+1;
    }
}
cout<<min;

}// output coming out to be 7 for test case 10 4 1 2 3 4