cf. #304 div.2

来源:互联网 发布:js异步 编辑:程序博客网 时间:2024/04/29 22:41

题目链接:http://codeforces.com/contest/546点击打开链接


前三题难度不大,不过时间只有2小时,看来我是得加快做题的效率呀奋斗


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 buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).

He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?

Input

The first line contains three positive integers k, n, w (1  ≤  k, w  ≤  10000 ≤ 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, output 0.

Sample test(s)
input
3 17 4
output
13
B. Soldier and Badges
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness 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 integer n (1 ≤ n ≤ 3000).

Next line consists of n integers ai (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
2
Note

In first sample test we can increase factor of first badge by 1.

In second sample test we can increase factors of the second and the third badge by 1.



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 exactly n cards, numbered from 1 to nall 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 a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and 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 many fights will happen and who will win the game, or state that game won't end.

Input

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

Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.

Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.

All card values are different.

Output

If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.

If the game won't end and will continue forever output  - 1.

Sample test(s)
input
42 1 32 4 2
output
6 2
input
31 22 1 3
output
-1
Note

First sample:

Second sample:




//A. Soldier and Bananas#include <stdio.h>#include <math.h>int main(){    int k, w;    long long sum, n;    scanf("%d%lld%d", &k, &n, &w);    sum = 0;    for (int i = 1; i <= w; i++)        sum += k * i;    if (sum > n)        printf("%lld\n", sum - n);    else printf("0\n");}//B. Soldier and Badges#include <stdio.h>#include <algorithm>using namespace std;int cmp(int a, int b){    return a < b;}int main(){    int n, ans;    ans = 0;    int a[3005];    scanf("%d", &n);    for (int i = 0; i < n; i++)        scanf("%d", &a[i]);    sort(a, a+n, cmp);    for (int i = 0; i < n - 1; i++)        if (a[i] >= a[i+1]){            while (a[i+1] <= a[i]){                a[i+1] += 1;                ans += 1;            }        }    printf("%d\n", ans);}//C.Soldier and Cards
#include <stdio.h>#include <algorithm>#include <math.h>#include <queue>#include <string.h>using namespace std;typedef struct{    int s;}node;queue <node> q;queue <node> p;int vis[11][11];int main(){    int n;    scanf("%d", &n);        int ans = 0;        node map;        int k1, k2;        scanf("%d", &k1);        for (int i = 0; i < k1; i++){            scanf("%d", &map.s);            p.push(map);        }        scanf("%d", &k2);        for (int i = 0; i < k2; i++){            scanf("%d", &map.s);            q.push(map);        }        while (1){            if(p.empty()){                printf("%d 2\n", ans);                break;            }            if(q.empty()){                printf("%d 1\n", ans);                break;            }            node tmpa = p.front();            node tmpb = q.front();            if(ans > 1000000){                printf("-1\n");                break;            }            vis[tmpa.s][tmpb.s] = 1;            q.pop();            p.pop();            ans += 1;            if (tmpa.s > tmpb.s){                p.push(tmpb);                p.push(tmpa);            }            else{                q.push(tmpa);                q.push(tmpb);            }        }    }


0 0