zoukankan      html  css  js  c++  java
  • B. Valera and Contest

    B. Valera and Contest
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.

    After the contest was over, Valera was interested in results. He found out that:

    • each student in the team scored at least l points and at most r points;
    • in total, all members of the team scored exactly sall points;
    • the total score of the k members of the team who scored the most points is equal to exactly sk; more formally, if a1, a2, ..., an is the sequence of points earned by the team of students in the non-increasing order (a1 ≥ a2 ≥ ... ≥ an), then sk = a1 + a2 + ... + ak.

    However, Valera did not find out exactly how many points each of n students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.

    Input

    The first line of the input contains exactly six integers n, k, l, r, sall, sk (1 ≤ n, k, l, r ≤ 1000; l ≤ r; k ≤ n; 1 ≤ sk ≤ sall ≤ 106).

    It's guaranteed that the input is such that the answer exists.

    Output

    Print exactly n integers a1, a2, ..., an — the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.

    Sample test(s)
    Input
    5 3 1 3 13 9
    Output
    2 3 2 3 3 
    Input
    5 3 1 3 15 9
    Output
    3 3 3 3 3 
    #include <iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #define maxn 1010
    #define LL long long
    #define mod 1000000007
    using namespace std ;
    
    int ans[maxn] , tt , mm , sk , ll ;
    bool getans( int u , int L , int R )
    {
        if( mm == sk ) return true ;
    
            ans[u]++ ;
            mm++ ;
            if(tt)tt-- ;
            else
            {
                ans[ll]-- ;
                if(ans[ll] <= L) ll-- ;
            }
            if(mm == sk ) return true ;
            return false ;
    }
    int main()
    {
       int i , n ,m , j , k;
       int L , R , sum ;
      // freopen("in.txt","r",stdin) ;
       while( scanf("%d%d%d%d%d%d" , &n,&k,&L,&R,&sum,&sk ) != EOF )//n, k, l, r, sall, sk
       {
            j = sum/n ;
            tt = sum%n ;
            mm = 0 ;
            ll = n ;
            for( i = 1 ; i <= n ;i++ ){
                ans[i] = j ;
                if(i <= k) mm += j ;
            }
            i = 1 ;
              while(1){
                if(getans(i,L,R))break ;  // 每次都给一个增加1 
                  i++ ;
                if( i > k ) i = 1 ;
              }
            
           if(tt)
            {
                for( i = k+1 ; i <= n ;i++ )
                {
                    while( ans[i] < ans[k])
                    {
                        ans[i]++ ;
                        tt-- ;
                        if(tt==0) break ;
                    }
                    if(tt==0)break ;
                }
            }
            
         for( i = 1 ; i < n ;i++ ){
              printf("%d " ,ans[i]) ;
            }
            cout << ans[i] << endl ;
       }
       return 0 ;
    }
    
  • 相关阅读:
    直播软件源码开发,搭建多类型直播平台用途发广泛
    直播平台源代码,搭建部署直播系统的基石
    直播系统应用领域广泛,开发时有哪些事项需要注意
    搭上直播带货系统源码开发的这班车,这些事你要知道
    小视频app源码具备的优势让短视频系统更受欢迎
    开发视频直播系统,视频直播系统源码是核心技术
    直播平台源代码开发,支持全终端观看及提高开屏流畅度很重要
    一对一源码开发,一对一直播系统如何在直播领域站稳脚跟
    直播带货系统,实现运营级低延时直播需要这些技术
    梳理直播带货源码开发直播系统的相关知识点
  • 原文地址:https://www.cnblogs.com/20120125llcai/p/3450715.html
Copyright © 2011-2022 走看看