Submission #484124

#TimeUsernameProblemLanguageResultExecution timeMemory
484124MilosMilutinovicJob Scheduling (CEOI12_jobs)C++14
0 / 100
153 ms31940 KiB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=1010000;
int n,d,m,a[N];
VI qs[N];
bool check(int x) {
	deque<int> dq;
	rep(i,1,n+1) {
		for (auto x:qs[i]) dq.pb(i+d-1);
		rep(j,0,min(SZ(dq),x)) {
			if (dq[0]<i) return false;
			dq.pop_front();
		}
	}
	return dq.empty();
}
int main() {
	scanf("%d%d%d",&n,&d,&m);
	rep(i,1,m+1) scanf("%d",a+i),qs[a[i]].pb(i);
	int l=1,r=m;
	while (l+1<r) {
		int md=(l+r)>>1;
		if (check(md)) r=md;
		else l=md;
	}
	printf("%d",r);
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
*/

Compilation message (stderr)

jobs.cpp: In function 'bool check(int)':
jobs.cpp:28:13: warning: unused variable 'x' [-Wunused-variable]
   28 |   for (auto x:qs[i]) dq.pb(i+d-1);
      |             ^
jobs.cpp: In function 'int main()':
jobs.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  scanf("%d%d%d",&n,&d,&m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
jobs.cpp:38:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  rep(i,1,m+1) scanf("%d",a+i),qs[a[i]].pb(i);
      |               ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...