Codeforces Round #452 (Div. 2) A,b,c

Source: Internet
Author: User
Tags time limit
A. Splitting in Teams time limit per test 1 second memory limit per test, megabytes input standard input output Standar D Output

There were n groups of students which came to write a training contest. A Group is either one person who can write the contest with anyone else, or both people who want to write the contest in th E same team.

The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible so he can ' t use any groups to form teams. For groups of both, either both students should write the contest, or both should not. If the students from a group of the contest, they should is in the same team. Input

The first line contains a single integer n (2≤n≤2 105)-the number of groups.

The second line contains a sequence of integers A1, A2, ..., an (1≤ai≤2), where AI was the number of people in Group I. Output

Print The maximum number of teams of three people the coach can form. Examples input

4
1 1) 2 1
Output
1
Input
2
2 2
Output
0
Input
7
2 2 2 1 1 1 1
Output
3
Input
3
1 1 1
Output
1
Note

In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.

In the second example he can ' t make a single team.

In the third example the coach can form three teams. For example, he can does this in the following Way:the first group (of both people) and the seventh group (of one person), T He second group (of People) and the sixth group (of one person), the third group (of the People) and the fourth group (of one person).
The puzzle: The number of records 1 and 2 is one and both, compare the number of one and the other, if the number is large, then the final quantity is one, if one is larger, then the last number is a one-two/3; code

#include <cstdio>
#include <algorithm>
#define M 200010

using namespace std;

int a[m];

int main ()
{
    int n;
    scanf ("%d", &n);
    int one = 0;
    int: 0;
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        scanf ("%d", &a[i]);
        if (a[i] = = 1) one++;
        else two++;
    }
    if (>= one) cnt + = one;
    else
    {
        cnt = cnt + N;
        CNT = cnt + (one-two)/3;
    }
    printf ("%d\n", CNT);
    return 0;

}



B. Months and years time limit per test 1 second memory limit per test megabytes input standard input output standard Output

Everybody in Russia uses Gregorian calendar. In this calendar there was in January, 3 or more days in February (depending on whether the year is leap 1 days in March, and in April, for days in the May, and in June, and in July, and in August, and in September, and October, 3 0 in November, to December.

A year is the leap in one of the Cases:either its number is divisible by 4, and not the divisible by, or was divisible by 400. For example, the following years is leap:2000, 2004, but years 1900 and 2018 is not leap.

In this problem given n (1≤n≤24) integers a1, A2, ..., an, and if these integers could is du Rations in days of nconsecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there are a month in some year, such, it duration is A1 days, duration of the next month is a 2 days, and so on. Input

The first line contains a single integer n (1≤n≤24)-the number of integers.

The second line contains n integers a1, a2, ..., an (28≤ai≤31)-the numbers your is to check. Output

If There is several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).

You can print the arbitrary case (small or large). Examples input

4
31 31) 30 31
Output
Yes

Input
2
30 30
Output
No

Input
5
29 31 30 31 30
Output
Yes

Input
3
31 28 30
Output
No

Input
3
31 31 28
Output
Yes

Note

In the first example the integers can denote months July, August, September and October.

The second example the answer is no, because there is no, and consecutive months each have a.

In the third example, the months Are:february (leap year)-march-april–may-june.

In the fourth example the number of days in the second month is to be, so it is February. March follows February and has been, but not in, so the answer is NO.

In the fifth example, the months Are:december-january-february (non-leap year).

The question: write the month as a ring, use an array, and then match the month to check with the array, if it matches (the substring of the array) is a continuous

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.