Div2 codeforces codeforces Round #407 __codeforces

Source: Internet
Author: User
A. Anastasia and PebblesTime Limit/test 1 second memory limit per test 256 megabytes input standard input output standard output

Anastasia loves going for a walk in, Uzhlyandian Park. But She became uninterested walking, so she began to collect Uzhlyandian. At the A, she decided to collect all the pebbles she could find in the park.

She has only two pockets. She can put on most k pebbles in the same time. There are n different pebble types in the park, and There wi are of the pebbles type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can ' t spend all her time collecting pebbles, so she can collect pebbles to the park only once a day.

Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Sideration that Anastasia can ' t place pebbles of the different types in same pocket. Input

The "I" contains two integers n and K (1≤n≤105, 1≤k≤109)-the number of different pebble types and Of Pebbles Anastasia can place in one pocket.

The second line contains n integers w1, w2, ..., WN (1≤wi≤104)-number of pebbles of each type. Output

The only line of output contains one integer-the minimum number of days Anastasia needs to collect all the pebbles. Examples input

3 2
2 3 4
Output
3
Input
5 4
3 1 8 9 7
Output note

In the ' the ', Anastasia can collect all pebbles of the the ' the ' the ' the ' the ' the ' the ' the ' the ' the ' the ' the ' the ' Cond Day, and of third type-on the third day.

Optimal sequence of actions in the second sample Case:in the ' the ' the ' the ' Anastasia collects 8 pebbles of the third type. The second day she collects 8 pebbles of the fourth type. The third day she collects 3 pebbles of the The ' the ' the ' the ' and 1 pebble of the fourth type. The fourth day she collects 7 pebbles of the fifth type.

The fifth day she collects 1 pebble of the second type.
Problem: Water problems.

#include <bits/stdc++.h>
using namespace std;
int n,k;
int EXM;
int main ()
{
    scanf ("%d%d", &n,&k);
    int ans=0;
    for (int i=1;i<=n;i++) {
        scanf ("%d", &EXM);
        ans=ans+exm/k;
        if (exm%k)
            ans++;
    }
    int re=0;
    RE=ANS/2;
    if (ans%2) re++;
    printf ("%d\n", re);
    return 0;
}



B. Masha and geometric depression time limit/test 1 second memory limit per test 256 megabytes input Standard input OU Tput Standard Output

Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.

You are are given geometric progression B defined by two integers b1 and Q. Remind this a geometric progression is a sequence of INTEGERSB1, B2, B3, ..., where for all I > 1 the respective term satisfies the condition bi = bi-1 q, where Q is Called the common ratio of the progression. Progressions in Uzhlyandia are Unusual:both B1 and Q can equal 0. Also, Dvastan gave Masha m "bad" INTEGERSA1, A2, ..., am, and an integer L.

Masha writes all progression terms one through one onto the board (including repetitive) while condition |bi| ≤l is satisfied (|x| means absolute value of x). There is a exception:if a term equals one of the "bad" integers, Masha skips it (doesn ' t write onto the board) and moves Forward to the next term.

But the "lesson is going" to "soon, so Masha has to calculate how many, and would be integers on the written. In depression, Masha asked for help:help her calculate how many numbers she'll write, or prin T "INF" in case she needs to write infinitely many integers. Input

The "a" of input contains four integers b1, q, L, m ( -109≤b1, q≤109, 1≤l≤109, 1≤m≤105)-the initial Te RM and the common ratio of progression, absolute value of maximal number that can is written on the board and the number O F "bad" integers, respectively.

The second line contains m distinct integers a1, A2, ..., AM ( -109≤ai≤109)-numbers that would never is written on the Board. Output

Print the only integer, meaning the number of progression terms that'll be written on the board if it is finite, or "inf "(without quotes) otherwise. Examples input

3 2 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11-5453 141245
Output
0
Input
123 1 2143435 4
54343-13 6 124
Output
Inf
Note

In the ' the ', Masha'll write integers 3, 12, 24. Progression term 6 would be skipped because it are a "bad" integer. Terms bigger than won ' t was written because they l by exceed value.

In the second case, Masha won ' t-write any number because the all terms are equal and ' a ' bad ' integer.

In the third case, Masha'll write infinitely integers 123.
The puzzle: Still very water ....

#include <bits/stdc++.h>
#define LL __int64
using namespace std;
ll B1,q,l,m;
ll tmp;
map<ll,int>mp;
ll Ans=0;
int main ()
{
    scanf ("%i64d%i64d%i64d%i64d", &b1,&q,&l,&m);
    for (ll i=1;i<=m;i++) {
        scanf ("%i64d", &tmp);
        mp[tmp]=1;
    }
    for (int i=1;i<=1000;i++) ans=0;
    for (int i=0;i<501;i++) {
        if (ABS (B1) >l) break;
        if (mp[b1]!=1) ans++;
        b1*=q;
    }
    if (ans>100) printf ("inf\n");
    else printf ("%i64d\n", ans);
    return 0;
}


C. Functions again time limit/test 1 second memory limit per test 256 megabytes input standard input output

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.