Wrong Answer when submitted although i am getting correct answer when i try with some examples.
Here is my code. I have used the greedy approach.
#include <bits/stdc++.h>
using namespace std;
bool mycomparator( pair<double,double> &a ,pair<double,double> &b ){
if(a.first>b.first)return true;return false;
}
vector<pair<double,double>> p (500003) ;
vector ba(500003);//represents the number ballots in ith city
int main() {int n , b;
cin>>n>>b;
while(n!=-1 && b!=-1)
{
for(int i=0;i<n;i++){cin>>p[i].first;p[i].second=p[i].first;ba[i]=1; }
sort(p.begin(),p.begin()+n,mycomparator);
int ballot=n;
while(ballot<b)
{for(int i=0;i<n;i++)
{while(p[i].second>=p[(i+1)%n].second && ballot<b )
{ ba[i]++;
p[i].second=p[i].first/ba[i];//cout<<p[i].second<<" ";
ballot++;
}
}
}
double maxi=INT_MIN;
for(int i=0;i<n;i++)
{if(p[i].second>maxi)maxi=p[i].second;}
cout<<ceil(maxi)<<endl;
cin>>n>>b; }
return 0;
}