1.题目描述:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8.
For instance, if Noora has marks [8, 9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8, 8, 9], Noora will have graduation certificate with 8.
To graduate with «A» certificate, Noora has to have mark k.
Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k.
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ k) denoting marks received by Noora before Leha's hack.
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.
2 10 8 9
4
3 5 4 4 4
3
Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9,
so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4marks
in total) to the registry, achieving Noora having average mark equal to .
Consequently, new final mark is 10. Less number of marks won't fix the situation.
In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
2.题意概述:
给你某同学成绩n门,告诉你取整规则即当k≥下取整[k]+0.5时,k取上取整(k),问你在这种规则下,这个同学至少还要靠几门分数为k的成绩使得它的平均分按照这种计算方法达到分数k?
3.解题思路:
如果要增加,肯定也是加完以后分数平均分正好为下取整[k]+0.5时是最小的。我们假设增加x门,用sum表示原先这些成绩,则有,解出来
,但是这仅仅是当需要增加时候,因为不需要增加时候这个解是负数(掉到这个坑里了QAQ),特判一下就行。
4.AC代码:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100010
#define lson root << 1
#define rson root << 1 | 1
#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long _begin_time = clock();
#endif
int n, k;
while (~scanf("%d%d", &n, &k))
{
int sum = 0;
for (int i = 0; i < n; i++)
{
int x;
scanf("%d", &x);
sum += x;
}
int ans = (2 * k - 1) * n - 2 * sum;
printf("%d\n", ans < 0 ? 0 : ans);
}
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return 0;
}