216C - Hiring Staff - CodeForces Solution


greedy *1800

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <cfloat>
#include <sstream>

using namespace std;

int n, m, i, j, k;
string s, p;
long long M = 1000000007;

void sim()
{
    vector<int> ans;
    set<pair<int, int>> work, rest;
    i = 1;
    while (i <= n + m)
    {
        while (rest.size() && (*rest.begin()).first + m == i)
        {
            pair<int, int> x = *rest.begin();
            rest.erase(x);
            work.insert({i, x.second});
        }
        while (work.size() && (*work.begin()).first + n == i)
        {
            pair<int, int> x = *work.begin();
            work.erase(x);
            rest.insert({i, x.second});
        }
        int f = 0;
        for (auto itr = work.begin(); itr != work.end(); itr++)
            if ((*itr).first + n == i + 1)
                f++;
        if (f == work.size())
        {
            ans.push_back(i);
            work.insert({i, ans.size()});
        }
        while (work.size() < k)
        {
            ans.push_back(i);
            work.insert({i, ans.size()});
        }
        i++;
    }
    cout << ans.size() << "\n";
    for (i = 0; i < ans.size(); i++)
        cout << ans[i] << " ";
    return;
}

void solve(int T)
{
    cin >> n >> m >> k;
    sim();
    return;
}

int main()
{
    cin.sync_with_stdio(false);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    t = 1;
    for (int i = 1; i <= t; i++)
    {
        solve(t);
        cout << "\n";
    }
}


Comments

Submit
0 Comments
More Questions

1516B - AGAGA XOOORRR
1515A - Phoenix and Gold
1515B - Phoenix and Puzzle
155A - I_love_username
49A - Sleuth
1541A - Pretty Permutations
1632C - Strange Test
673A - Bear and Game
276A - Lunch Rush
1205A - Almost Equal
1020B - Badge
1353A - Most Unstable Array
770A - New Password
1646B - Quality vs Quantity
80A - Panoramix's Prediction
1354B - Ternary String
122B - Lucky Substring
266B - Queue at the School
1490A - Dense Array
1650B - DIV + MOD
1549B - Gregor and the Pawn Game
553A - Kyoya and Colored Balls
1364A - XXXXX
1499B - Binary Removals
1569C - Jury Meeting
108A - Palindromic Times
46A - Ball Game
114A - Cifera
776A - A Serial Killer
25B - Phone numbers