Given an integer array representing size of candles which reduce 1 unit in a day. Room is illuminated using given x candles. Question is to find maximum number of days room is without darkness.
Input:
The first line of input consists of an integer T denoting the number of test cases Each test case contains an integer N denoting the size of the array. Then in the next line are N space separated elements of the array.
The first line of input consists of an integer T denoting the number of test cases Each test case contains an integer N denoting the size of the array. Then in the next line are N space separated elements of the array.
Output:
For each test case print the maximum number of days room will be illuminated in a new line.
Constraints:
1<=T<=200
1<=N<=1000
1<=Elements of array <=10^7
For each test case print the maximum number of days room will be illuminated in a new line.
Constraints:
1<=T<=200
1<=N<=1000
1<=Elements of array <=10^7
Example:
Input:
1
5
2 3 4 1 2
Output:
4
Input:
1
5
2 3 4 1 2
Output:
4
Your code
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int i;
long long int a[1000];
for(i=0; i<n; i++)
{
cin>>a[i];
}
long long int ans=-1;
for(i=0; i<n; i++)
{
ans=max(ans,a[i]);
}
cout<<ans<<endl;
}
return 0;
}