Submission #257207

# Submission time Handle Problem Language Result Execution time Memory
257207 2020-08-03T20:45:04 Z Lawliet Job Scheduling (CEOI12_jobs) C++17
100 / 100
207 ms 13816 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;

const int MAXN = 100010;
const int MAXM = 1000010;

int n, m, d;

int sQtd[MAXN];

vector<int> day[MAXN];

bool test(lli k)
{
	lli mn = 0;

	for(int i = 1 ; i <= n ; i++)
	{
		lli curValue = sQtd[i] - k*i - k*d;
		if( curValue > mn ) return false;

		mn = min( mn , sQtd[i] - k*i );
	}

	return true;
}

int bs()
{
	int l = 1;
	int r = m;

	while( l < r )
	{
		int m = ( l + r )/2;

		if( test( m ) ) r = m;
		else l = m + 1;
	}

	return r;
}

int main()
{
	scanf("%d %d %d",&n,&d,&m);

	for(int i = 1 ; i <= m ; i++)
	{
		int d;
		scanf("%d",&d);

		day[d].push_back( i );
	}

	for(int i = 1 ; i <= n ; i++)
		sQtd[i] = sQtd[i - 1] + (int)day[i].size();

	int ans = bs();

	printf("%d\n",ans);

	queue<int> cur;

	for(int i = 1 ; i <= n ; i++)
	{
		for(int j = 0 ; j < (int)day[i].size() ; j++)
			cur.push( day[i][j] );

		for(int k = 1 ; k <= ans && !cur.empty() ; k++)
		{
			printf("%d ",cur.front());
			cur.pop();
		}

		printf("0\n");
	}
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&d,&m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
jobs.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&d);
   ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4080 KB Output is correct
2 Correct 24 ms 4080 KB Output is correct
3 Correct 23 ms 4080 KB Output is correct
4 Correct 25 ms 4216 KB Output is correct
5 Correct 23 ms 4088 KB Output is correct
6 Correct 24 ms 4088 KB Output is correct
7 Correct 23 ms 4080 KB Output is correct
8 Correct 23 ms 4216 KB Output is correct
9 Correct 27 ms 4480 KB Output is correct
10 Correct 27 ms 4472 KB Output is correct
11 Correct 26 ms 3840 KB Output is correct
12 Correct 53 ms 4984 KB Output is correct
13 Correct 72 ms 6904 KB Output is correct
14 Correct 123 ms 8184 KB Output is correct
15 Correct 133 ms 9080 KB Output is correct
16 Correct 157 ms 10744 KB Output is correct
17 Correct 191 ms 12664 KB Output is correct
18 Correct 184 ms 12536 KB Output is correct
19 Correct 207 ms 13816 KB Output is correct
20 Correct 187 ms 12792 KB Output is correct