369B - Valera and Contest - CodeForces Solution


constructive algorithms implementation math *1400

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <unordered_map>
#include<bitset>
#include <unordered_set>
#define Fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define sortvector(v) sort(v.begin(),v.end())
#define sortrvector(v) sort(v.rbegin(),v.rend())
#define loop(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int>
typedef long long  ll;
const ll MOD = 1000000007;
using namespace std;
const int N = 100+8;
bool prime[N];
void Sieve()
{
    memset(prime, 1, sizeof(prime));
    prime[0] = prime[1] = false;
    for (int i = 2; i < N; i++) {
        if (prime[i]) {
            for (ll j = 1ll * i * i; j < N; j += i)
                prime[j] = false;
        }
    }
}
ll binaryexponentialpower(int base, int power)
{
    ll result = 1;
    while (power > 0) {
        if (power & 1)
            result *= base;
        base *= base;
        power /= 2;
    }
    return result;
}
ll __gcd(ll a, ll b) {
    while (b != 0)
    {
        ll a2 = a;
        a = b;
        b = a2 % b;
    }
    return a;
}
int GetDivisors(ll x) {
    set<int>s;
    for (ll i = 1; i * i <= x; i++) {
        if (x % i == 0)
        {
            s.insert(i);
            if (x / i != i)
            {
                s.insert(x / i);
            }
        }
    }
    return s.size();
}
//ll n;
//void solve(int length ,int level) {
//    if (level == n)
//        return;
//    for (int i = 0; i < length - 1; i++)
//        cout << ' ';
//    for (int i = 0; i < 2 * level + 1; i++)
//        cout << '*';
//    cout << '\n';
//    solve(length - 1, ++level);
//}
int main() {

    Fast
        /*freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);*/
        int t = 1;

    //cin >> t;
    while (t--) {
        int mini = 1e6 + 1;
        int n, k, l, r, sall, sk;
        cin >> n >> k >> l >> r >> sall >> sk;
        vi v(n);
        int add = sk / k;
        int mod = sk % k;
        sall -= sk;
        for (int i = 0; i < k && sk>0; i++) {
            v[i] = add + (mod > 0);
            mod--;
        }
        if (k != n) {
            add = sall / (n - k);
            mod = sall % (n - k);
            for (int i = k; i < n; i++) {
                v[i] = add + (mod > 0);
                mod--;
            }
        }
        for (auto x : v)
            cout << x << ' ';
        
    }
}


Comments

Submit
0 Comments
More Questions

938A - Word Correction
159C - String Manipulation 10
258A - Little Elephant and Bits
1536C - Diluc and Kaeya
1428C - ABBB
1557A - Ezzat and Two Subsequences
255A - Greg's Workout
1059A - Cashier
1389C - Good String
1561A - Simply Strange Sort
1337B - Kana and Dragon Quest game
137C - History
1443C - The Delivery Dilemma
6C - Alice Bob and Chocolate
1077C - Good Array
285B - Find Marble
6A - Triangle
1729A - Two Elevators
1729B - Decode String
1729C - Jumping on Tiles
1729E - Guess the Cycle Size
553B - Kyoya and Permutation
1729D - Friends and the Restaurant
1606C - Banknotes
580C - Kefa and Park
342A - Xenia and Divisors
1033A - King Escape
39D - Cubical Planet
1453A - Cancel the Trains
645A - Amity Assessment