# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
635277 | Anthony_Liu | Job Scheduling (CEOI12_jobs) | C++11 | 222 ms | 7364 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>
using namespace std;
#define f first
#define s second
#define ll long long
#define pb push_back
#define pi pair <int,int>
#define vi vector <int>
#define size(x) (int)(x).size()
#define all(x) x.begin(), x.end()
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0);
if (size(name)) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
int N, D, M;
vector <pi> v;
bool check(int m)
{
priority_queue <int> waiting;
for (int i=0; i<M; )
{
/*/
if (m == 2)
{
if (!waiting.empty()) cout<<-waiting.top()<<'\n';
else cout<<"empty"<<'\n';
cout<<"size: "<<size(waiting)<<'\n';
}
/*/
int cur = 0;
int tmp = v[i].f;
while (!waiting.empty()) {
if (cur >= m) break;
waiting.pop();
++cur;
}
if (! waiting.empty() && -waiting.top()+D <= v[i].f)
return false;
while (v[i].f == tmp) {
if (cur < m) {
++cur;
++i;
continue;
}
waiting.push(-v[i].f);
++i;
}
}
return (size(waiting) <= m);
}
int main()
{
setIO();
cin>>N>>D>>M;
v.resize(M);
for (int i=0; i<M; i++) {
cin>>v[i].f;
v[i].s = i;
}
sort (all(v));
//for (auto k:v) cout<<k.f<<" "; cout<<'\n';
int l = 1, r = M, m, ans;
while (l <= r)
{
m = l+(r-l)/2;
//cout<<m<<'\n';
if (check(m)) {
ans = m;
r = m-1;
}
else l = m+1;
}
cout<<ans<<"\n";
return 0;
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |