codeforces 810A Straight «A»

本文介绍了一个算法,用于计算学生Noora需要获得多少额外的最佳分数,以便她的最终平均分数达到最高分k,涉及四舍五入处理。

网址:点击打开链接

A. Straight «A»
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.

Examples
input
2 10
8 9
output
4
input
3 5
4 4 4
output
3
Note

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.


题意:有了n个数的和,求再添加几个最大值(k),得到的平均值为k,包含四舍五入。

#include<stdio.h>
#include<math.h>
int main()
{
    int n,k,a[110],sum=0;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    int x=0;
    while(1)
    {
        double w=(double)(sum+x*k)/(n+x);
        if(floor(w+0.5)==k)
            break;
        else
            x++;
    }
    printf("%d\n",x);
    return 0;
}



### Codeforces Contest 370 Problem A: "Ksenia and Pan Scales" 在Codeforces竞赛370中的问题A,题目名为“Ksenia and Pan Scales”,要求解决一个关于天平的问题。具体来说,问题是围绕天平的平衡条件展开的,需要判断给定的一组重量是否能够使天平保持平衡[^1]。 #### 问题描述 给定一个字符串 `s` 表示天平的状态,其中包含字符 `'.'` 和 `'*'`。字符 `'.'` 表示空位,而字符 `'*'` 表示放置了砝码的位置。任务是检查是否存在一种方法,通过将砝码分配到天平的两侧,使得天平达到平衡状态。 #### 解决方案 解决方案的核心思想是模拟天平的工作原理,并计算左右两边的力矩差值。以下是具体的实现步骤: 1. 首先,遍历字符串 `s`,统计左侧和右侧的力矩。 2. 如果左右力矩相等,则输出 `"YES"`,否则输出 `"NO"`。 以下是实现该算法的代码示例: ```python def solve_pan_scales(s): left_torque = 0 right_torque = 0 n = len(s) for i in range(n): if s[i] == '*': if i < n // 2: left_torque += (n // 2 - i) elif i > n // 2: right_torque += (i - n // 2) if left_torque == right_torque: return "YES" else: return "NO" # 示例输入 s = input().strip() print(solve_pan_scales(s)) ``` 此代码通过计算天平两侧的力矩来判断是否可以达到平衡状态[^2]。 #### 注意事项 - 输入字符串的长度为奇数,确保天平中心点明确。 - 确保正确处理边界情况,例如所有砝码都在一侧的情况。 ### 结论 通过上述方法,可以有效地解决 Codeforces Contest 370 Problem A 的问题。该方法的时间复杂度为 O(n),满足题目对时间限制的要求[^3]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值