Providing gifts
You are given
coins whose values are from to . The value of each coin ranges from to . You want to gift as many people as you can.
You also want to be fair with everyone and therefore, you prepare the gift such that each person can be gifted the same amount of money. You are allowed to put several denominations together in a gift. What is the maximum number of gifts that you can prepare?
Note: It does not make sense to prepare empty gifts.
Input format
- The first line contains denoting the number of test cases.
- The first and only line of each test case contains an integer as described in the problem statement.
Output format
For each test case, print a single integer consisting of the maximum number of gifts.
Constraints
Suppose you decide that each gift should be worth 3 units. We can put (1,2) in one gift and (3) in another so we will have 2 gifts. There is no more optimal strategy.
Problem Link : https://www.hackerearth.com/practice/algorithms/greedy/basics-of-greedy-algorithms/practice-problems/algorithm/monotization-065bcc29/
Solution :
If N is even answer is N/2 else answer is (N-1)/2 +1.
We will always aim for making each gift of value N.
we will club (1,N-1) , (2,N-2) ....
Answer :
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define endl "\n"
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
int main() {
FIO;
test
{
ll n;
cin>>n;
++n;
n/=2;
cout<<n<<endl;
}
return 0;
}
t = int(input())
while t > 0:
t -= 1
n = int(input())
print((n + 1) // 2)