zoukankan      html  css  js  c++  java
  • A. Ilya and Diplomas( Codeforces Round #311 (Div. 2) )

    A. Ilya and Diplomas
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Soon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there.

    At a meeting of the jury of the Olympiad it was decided that each of the n participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma.

    They also decided that there must be given at least min1 and at most max1 diplomas of the first degree, at least min2 and at mostmax2 diplomas of the second degree, and at least min3 and at most max3 diplomas of the third degree.

    After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree.

    Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations.

    It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all nparticipants of the Olympiad will receive a diploma of some degree.

    Input

    The first line of the input contains a single integer n (3 ≤ n ≤ 3·106) — the number of schoolchildren who will participate in the Olympiad.

    The next line of the input contains two integers min1 and max1 (1 ≤ min1 ≤ max1 ≤ 106) — the minimum and maximum limits on the number of diplomas of the first degree that can be distributed.

    The third line of the input contains two integers min2 and max2 (1 ≤ min2 ≤ max2 ≤ 106) — the minimum and maximum limits on the number of diplomas of the second degree that can be distributed.

    The next line of the input contains two integers min3 and max3 (1 ≤ min3 ≤ max3 ≤ 106) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed.

    It is guaranteed that min1 + min2 + min3 ≤ n ≤ max1 + max2 + max3.

    Output

    In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.

    The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.

    Sample test(s)
    input
    6
    1 5
    2 6
    3 7
    
    output
    1 2 3 
    
    input
    10
    1 2
    1 3
    1 5
    
    output
    2 3 5 
    
    input
    6
    1 3
    2 2
    2 2
    
    output
    2 2 2 
    
    
       题意:给出3个区间 [L1,R1],[L2,R2],[L3,R3] 和正整数n,要求在3个区间内各选一个正整数。使得选出来的数之和为n。假设有多种选法,取从第一个区间内选出的
    
    
    
    #include<iostream>
    #include<algorithm>
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    
    using namespace std;
    
    int n;
    struct node
    {
        int minn;
        int maxx;
    }q[5];
    
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            for(int i=1;i<=3;i++)
            {
                scanf("%d%d",&q[i].minn,&q[i].maxx);
            }
            int a[5];
            int sum = n;
            memset(a,0,sizeof(a));
            for(int i=1;i<=3;i++)
            {
                a[i] = q[i].minn;
                sum -= a[i];
            }
            for(int i=1;i<=3;i++)
            {
                int num = q[i].maxx - q[i].minn;
                if(sum>=num)
                {
                    a[i] += num;
                    sum -= num;
                }
                else
                {
                    a[i] += sum;
                    break;
                }
            }
            printf("%d %d %d
    ",a[1],a[2],a[3]);
        }
        return 0;
    }


  • 相关阅读:
    printf()函数不能直接输出string类型
    HDU 6166.Senior Pan()-最短路(Dijkstra添加超源点、超汇点)+二进制划分集合 (2017 Multi-University Training Contest
    计蒜客 17119.Trig Function-切比雪夫多项式+乘法逆元 (2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F)
    POJ 1195.Mobile phones-二维树状数组
    HDU 1541.Stars-一维树状数组(详解)
    ACM中常见错误对应表
    HDU 6112.今夕何夕-蔡勒公式 (2017"百度之星"程序设计大赛
    hdu 2126 Buy the souvenirs 二维01背包方案总数
    codevs 1017 乘积最大 dp
    bzoj 2705: [SDOI2012]Longge的问题 欧拉函数
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/6921119.html
Copyright © 2011-2022 走看看