码迷,mamicode.com
首页 > 其他好文 > 详细

URAL 1991. The battle near the swamp

时间:2015-03-08 13:02:11      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

1991. The battle near the swamp

Time limit: 1.0 second
Memory limit: 64 MB
Gungan: Jar Jar, usen da booma!
Jar Jar: What? Mesa no have a booma!
Gungan: Here. Taken dis one.
In the battle with the Trade Federation, Queen Amidala decided to ask gungans for help. Jar Jar Binks escorted the Queen and her people to the holy place where they had an agreement. The gungans agreed to provide their army in order to get the droids of the Federation out from the capital. The gungan ruler Boss Nass was so grateful for uniting the nations that he appointed Jar Jar a general.
And here they are: two armies lined up along the bank of the swamp. The droids of the Federation are well-disciplined soldiers. They stand in neat formation, divided into n blocks of k droids each. The gungans have a foolproof weapon against droids, which is small energy balls called boom booms. One such ball can disable exactly one droid.
Jar Jar Binks also decided to split his army into n parts and give each part a task to destroy the corresponding block of droids. Each part received a truck with boom booms. Now help general Binks calculate the number of boom booms that will be left unused and the number of droids that will survive the attack. You can assume that when a boom boom is fired at a droid by a gungan, it always hits the target.

Input

The first line of the input contains numbers n and k (1 ≤ nk ≤ 10 000). The second line containsn numbers ai (0 ≤ ai ≤ 100 000) — the number of boom-booms in the i-th truck.

Output

Print two integers — the number of unused boom booms and the number of survived droids.

Sample

input output
4 5
2 7 5 0
2 8




题意:n支军队,每个军队ai个士兵,每个士兵能消灭一个敌人。每支军队要去的地方有k个敌人,问总共有多少士兵没用到,有多少敌人没被消灭。

解析:多出来的就是没用到的,不够的就是逃脱的敌人。



AC代码:

#include <cstdio>

int main(){
    int n, k, ans, anss, foo;
    while(scanf("%d%d", &n, &k)==2){
        ans = anss = 0;
        while(n--){
            scanf("%d", &foo);
            if(foo > k) ans += foo - k;
            else anss += k - foo;
        }
        printf("%d %d\n", ans, anss);
    }
    return 0;
}


URAL 1991. The battle near the swamp

标签:

原文地址:http://blog.csdn.net/u013446688/article/details/44132049

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!