# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
498111 | MohamedAliSaidane | Job Scheduling (CEOI12_jobs) | C++14 | 375 ms | 18376 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;
#define pb push_back
#define popb pop_back
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
int nx[4] = {1,-1,0,0}, ny[4] = {0,0,1,-1};
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;}
ll lcm(ll a, ll b){return (a / gcd(a, b)) * b;}
const int MAX_M = 1e6 + 4;
int n, d, m;
pii req[MAX_M];
map<int,int> key;
map<int,vi> cor;
bool test(int x)
{
int prec = 0;
set<pii> rq;
for(int i= 1; i <= n; i ++)
{
if(key.count(i) != 0)
rq.insert({i,key[i]});
int cur = x;
while(cur > 0 && !rq.empty())
{
pii u = *(rq.begin());
rq.erase(rq.begin());
if(cur >= u.ss)
{
cur -= u.ss;
}
else
{
rq.insert({u.ff,u.ss-cur});
cur = 0;
}
}
if(rq.empty())
continue;
if(i - ((*(rq.begin())).ff) > d)
return false;
if(i == n && !rq.empty())
return false;
}
return true;
}
void solve()
{
cin >> n>> d >> m;
for(int i = 0; i < m; i ++)
{
int x; cin >> x;
req[i] = {x,i+1};
cor[x].pb(i+1);
key[x] ++;
}
//for(auto e: req)
// cout << e.ff << ' ' << e.ss << '\n';
int debut = 1;
int fin = m;
int ans = m;
while(debut <= fin)
{
int mid = (debut+fin)/2;
if(test(mid))
{
ans = mid;
fin = mid -1;
}
else
debut = mid + 1;
}
cout << ans << '\n';
int cur = 0;
set<pii> s;
for(int i = 1; i <=n; i ++)
{
if(key.count(i) != 0)
{
for(auto e: cor[i])
s.insert({i,e});
}
int cur = ans;
while(cur != 0 && !s.empty())
{
cur --;
pii u = *(s.begin());
s.erase(s.begin());
cout << u.ss << ' ';
}
cout << "0\n";
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int tt = 1;
while(tt--)
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |