Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

problem in chef and integer problem

$
0
0
#include<iostream>
using namespace std;
int counting(long int[],unsigned long int);
int main()
{
unsigned long int n;
cin>>n;
long int* a=new long int[n];
for(int i=0;i<n;i++)
    cin>>a[i];
unsigned long int x;
cin>>x;
int sum=0;
int count=0;
count=counting(a,n);
while(count>=x)
{
  for(int i=0;i<n;i++)
        a[i]=a[i]+1;
count=counting(a,n);
sum+=x;

}
for(int i=0;i<n;i++)
{
    if(a[i]<0)
        sum-=a[i];
}
cout<<sum;
}
 int counting(long int a[],unsigned long int n)
 {
int count=0;
for(int i=0;i<n;i++)
    if(a[i]<0)
    count++;
return count;
}

Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>