#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
typedef long long ll;
typedef pair<int, int> pii;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
vector<pii> jobs;
int N, D;
bool ok(int x){
vector<int> last(x);
for(int i = 0; i < jobs.size(); i++){
int machine = i%x;
last[machine] = max(last[machine]+1, jobs[i].f);
if(last[machine] - jobs[i].f >= D)return false;
if(last[machine] > N)return false;
}
return true;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int M;
cin >> N >> D >> M;
for(int i = 0; i < M;i ++){
int x;
cin >> x;
jobs.pb({x,i});
}
sort(jobs.begin(), jobs.end());
int lo = 1;
int hi = 1000000;
while(lo < hi){
int mid = (lo+hi)/2;
if(ok(mid)){
//answer could be lower
hi = mid;
}
else{
lo = mid+1;
}
}
cout << lo << '\n';
//print(lo);
}
Compilation message
jobs.cpp: In function 'bool ok(int)':
jobs.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i = 0; i < jobs.size(); i++){
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
3176 KB |
Output isn't correct |
2 |
Incorrect |
24 ms |
3176 KB |
Output isn't correct |
3 |
Incorrect |
24 ms |
3176 KB |
Output isn't correct |
4 |
Incorrect |
24 ms |
3176 KB |
Output isn't correct |
5 |
Incorrect |
24 ms |
3196 KB |
Output isn't correct |
6 |
Incorrect |
27 ms |
3176 KB |
Output isn't correct |
7 |
Incorrect |
24 ms |
3176 KB |
Output isn't correct |
8 |
Incorrect |
24 ms |
3176 KB |
Output isn't correct |
9 |
Incorrect |
28 ms |
3304 KB |
Output isn't correct |
10 |
Incorrect |
30 ms |
3196 KB |
Output isn't correct |
11 |
Incorrect |
31 ms |
3176 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
64 ms |
3940 KB |
Output isn't correct |
13 |
Incorrect |
93 ms |
4700 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
134 ms |
5468 KB |
Output isn't correct |
15 |
Incorrect |
151 ms |
6360 KB |
Output isn't correct |
16 |
Incorrect |
190 ms |
8688 KB |
Unexpected end of file - int32 expected |
17 |
Incorrect |
238 ms |
8668 KB |
Unexpected end of file - int32 expected |
18 |
Incorrect |
250 ms |
8668 KB |
Unexpected end of file - int32 expected |
19 |
Incorrect |
277 ms |
9296 KB |
Output isn't correct |
20 |
Incorrect |
237 ms |
8668 KB |
Unexpected end of file - int32 expected |