# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
540450 | BhavayGoyal | Job Scheduling (CEOI12_jobs) | C++14 | 431 ms | 45448 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.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class T> using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define vii vector<vector<int>>
#define vi vector<int>
#define v vector
#define pii pair<int, int>
#define mii map<int, int>
#define umii unordered_map<int, int>
#define si set<int>
#define usi unordered_set<int>
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define endl "\n"
#define pb push_back
#define MOD 1000000007
int inf = 1e9;
int n, d, m;
v<pii> arr(m);
pair<bool, vii> isFiss(int mid)
{
int idx = 0;
vii answer(n);
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < mid; j++)
{
if (arr[idx].f > i) break;
if (i <= arr[idx].f + d) answer[i-1].pb(arr[idx++].s);
else return {false, answer};
if (idx == m) return {true, answer};
}
}
return {false, answer};
}
void sol()
{
cin >> n >> d >> m;
arr = v<pii>(m);
for (int i = 0; i < m; i++)
{
cin >> arr[i].f;
arr[i].s = i+1;
}
sort (all(arr));
int i = 1, j = m;
int ans = m;
vii actualans;
while (i <= j)
{
int mid = (i+j)/2;
auto f = isFiss(mid);
if (f.f)
{
actualans = f.s;
ans = mid;
j = mid-1;
}
else i = mid+1;
}
cout << ans << endl;
for (int i = 0; i < n; i++)
{
for (auto j : actualans[i]) cout << j << " ";
cout << 0 << endl;
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
t = 1;
// cin >> t;
for (int i = 1; i <= t; i++)
sol();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |