Codeforces Round #590 (Div. 3) A. Equalize Prices Again

link:

https://codeforces.com/contest/1234/problem/A

Meaning of the questions:

You are both a shop keeper and a shop assistant at a small nearby shop. You have n goods, the i-th good costs ai coins.

You got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. More precisely you decided to set the same price for all n goods you have.

However, you don't want to lose any money so you want to choose the price in such a way that the sum of new prices is not less than the sum of the initial prices. It means that if you sell all n goods for the new price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.

On the other hand, you don't want to lose customers because of big prices so among all prices you can choose you need to choose the minimum one.

So you need to find the minimum possible equal price of all n goods so if you sell them for this price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.

You have to answer q independent queries.

Ideas:

To find the average value rounded up.

Code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int n, sum = 0, a;
        scanf("%d", &n);
        for (int i = 1;i <= n;i++)
            scanf("%d", &a), sum += a;
        printf("%d\n", (sum+n-1)/n);
    }

    return 0;
}

Guess you like

Origin www.cnblogs.com/YDDDD/p/11618448.html