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 ;
}

 

posted @ 2013-11-30 10:34  _log__  阅读(181)  评论(0编辑  收藏  举报