Codeforce Round #216 Div2 B
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.
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.
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.
5 3 1 3 13 9
2 3 2 3 3
5 3 1 3 15 9
3 3 3 3 3
1 #include <cstdio> 2 #include <iostream> 3 #include <vector> 4 #include <set> 5 #include <cstring> 6 #include <string> 7 #include <map> 8 #include <cmath> 9 #include <ctime> 10 #include <algorithm> 11 #include <queue> 12 13 using namespace std; 14 #define INF 0x7fffffff 15 #define maxm 1001 16 #define mod 1000000007 17 #define mp make_pair 18 #define pb push_back 19 #define rep(i,n) for(int i = 0; i < (n); i++) 20 #define re return 21 #define fi first 22 #define se second 23 #define sz(x) ((int) (x).size()) 24 #define all(x) (x).begin(), (x).end() 25 #define sqr(x) ((x) * (x)) 26 #define sqrt(x) sqrt(abs(x)) 27 #define y0 y3487465 28 #define y1 y8687969 29 #define fill(x,y) memset(x,y,sizeof(x)) 30 31 typedef vector<int> vi; 32 typedef long long ll; 33 typedef long double ld; 34 typedef double D; 35 typedef pair<int, int> ii; 36 typedef vector<ii> vii; 37 typedef vector<string> vs; 38 typedef vector<vi> vvi; 39 40 template<class T> T abs(T x) { re x > 0 ? x : -x; } 41 42 const int maxn = 100015; 43 44 int n, m, t, k, x, l, r, s, sk; 45 int a[maxn], b[maxn]; 46 47 int main(){ 48 scanf("%d%d%d%d%d%d", &n, &k, &l, &r, &s, &sk); 49 int ans = s / n; 50 t = s - (ans*n); 51 for (int i = 0; i < n; i++)a[i] = ans; 52 for (int i = 0; i < t; i++)a[i]++; 53 int sum = 0; 54 for (int i = 0; i < k; i++)sum += a[i]; 55 if (sum != sk){ 56 sum = sk - sum; 57 t = sum / k; 58 for (int i = 0; i < k; i++)a[i] += t; 59 t = sum - t*k; 60 for (int i = k - 1; i >= k - t; i--)a[i]++; 61 t = sum / (n - k); 62 for (int i = k; i < n; i++)a[i] -= t; 63 t = sum - t*(n - k); 64 for (int i = k; i < k+t; i++)a[i]--; 65 } 66 for (int i = 0; i < n; i++)printf("%d ", a[i]); 67 return 0; 68 }
浙公网安备 33010602011771号