Submission #843587

#TimeUsernameProblemLanguageResultExecution timeMemory
843587vjudge1Job Scheduling (CEOI12_jobs)C++11
0 / 100
1052 ms22152 KiB
#include <bits/stdc++.h>
using namespace std;
#define num first
#define index second
vector<int> tmp_v;
bool is_ok(vector<pair<int,int>> a,int m,int d,int n)
{
	tmp_v.clear();
	int i=0;
	for(int cnt=1;cnt<=n;++cnt)
	{
		int tmp=m;
		while(tmp--) if(i<a.size())
		{
			if(a[i].num+d<cnt) return false;
			tmp_v.push_back(a[i++].index);
		}
		tmp_v.push_back(0);
	}
	return i>=a.size();
}
int main()
{
	int n,d,m;
	cin>>n>>d>>m;
	vector<pair<int,int>> a(m);
	vector<int> ans_v;
	for(int i=0;i<m;++i) cin>>a[i].num,a[i].index=i+1;
	sort(a.begin(),a.end());
//	for(auto it:a) cout<<it.num<<' '<<it.index<<'\n';
	int l=1,r=m,ans=m;
	while(l<=r)
	{
		int mid=(r-l)/2+l;
		if(is_ok(a,mid,d,n)) ans_v=tmp_v,ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans<<'\n';
	for(auto it:ans_v)
	{
		cout<<it<<' ';
		if(it==0) cout<<'\n';
	}
	return 0;
}
/*
8 2 12
1 1 2 2 2 3 3 4 4 5 6 6

8 2 12
1 2 4 2 1 3 5 6 2 3 6 4

2
5 1 0
9 4 0
2 10 0
6 12 0
3 7 0
11 8 0
0
0
*/

Compilation message (stderr)

jobs.cpp: In function 'bool is_ok(std::vector<std::pair<int, int> >, int, int, int)':
jobs.cpp:13:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |   while(tmp--) if(i<a.size())
      |                   ~^~~~~~~~~
jobs.cpp:20:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  return i>=a.size();
      |         ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...