Codeforces Round #304 (Div. 2) A,B,C题解

A. Soldier and Bananas

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

A soldier wants to buywbananas in the shop. He has to paykdollars for the first banana,2kdollars for the second one and so on (in other words, he has to payi·kdollars for thei-th banana).

He hasndollars. How many dollars does he have to borrow from his friend soldier to buywbananas?

Input

The first line contains three positive integersk,n,w(1≤k,w≤1000,0≤n≤109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.

Output

Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn’t have to borrow money, output0.

Sample test(s)

input

3 17 4

output

13

#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int main(){//freopen("i.txt", "r",stdin);//freopen("o.txt", "w",stdout);int k, n, w;scanf("%d%d%d", &k, &n, &w);long long sum = 0;for (int i = 1; i <= w; i++){sum += i*k;}if (sum>n)printf("%lld", sum-n);elseprintf("0");return 0;}

B. Soldier and Badges

time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Colonel hasnbadges. He wants to give one badge to every of hisnsoldiers. Each badge has acoolness factor, which shows how much it’s owner reached. Coolness factor can be increased by one for the cost of one coin.

For every pair of soldiers one of them should get a badge with strictly higher factor than the second one. Exact values of their factors aren’t important, they just need to have distinct factors.

Colonel knows, which soldier is supposed to get which badge initially, but there is a problem. Some of badges may have the same factor of coolness. Help him and calculate how much money has to be paid for making all badges have different factors of coolness.

Input

First line of input consists of one integern(1≤n≤3000).

Next line consists ofnintegersai(1≤ai≤n), which stand for coolness factor of each badge.

Output

Output single integer — minimum amount of coins the colonel has to pay.

Sample test(s)

input

41 3 1 4

output

1

input

51 2 3 2 5

output

2B题开始比赛后通过测试,,比赛完有一组数据TLE了,以下为超时的代码,我是想每次排序,找相同的数字,然后使后面+1,然而当数据差异很大是,排序的次数就会变得非常多。然后看了别人的代码,只需要排一次序,然后一直枚举前面与后面的数字,是所有的后面数字大于前面就跳出循环。{tt {{ans++;att sort}

#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int main(){//freopen("i.txt","r",stdin);//freopen("o.txt","w",stdout);int a[4000];int n;while(~scanf("%d",&n)){for(int i=1;i<=n;i++)scanf("%d",a+i);sort(a+1,a+n+1);int ans=0;for(int i=1;i<=n;i++){while(a[i]<=a[i-1]){++a[i];ans++;}}printf("%d\n",ans);}return 0;}

C. Soldier and Cards

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Two bored soldiers are playing card war. Their card deck consists of exactlyncards, numbered from1ton,all values are different. They divide cards between them in some manner, it’s possible that they have different number of cards. Then they play a "war"-like card game.

The rules are following. On each turn afighthappens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins thisfightand takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent’s card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player’s stack becomes empty, he loses and the other one wins.

You have to calculate how manyfightswill happen and who will win the game, or state that game won’t end.

Input

First line contains a single integern(2≤n≤10), the number of cards.

任何的限制,都是从自己的内心开始的。

Codeforces Round #304 (Div. 2) A,B,C题解

相关文章:

你感兴趣的文章:

标签云: