#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define pii pair<int,int>
using namespace std;
const int MAXN = 2e5+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;
int n,d,m;
vector<pii> niz;
vector<pii> kopija;
vector<pii> resenje;
bool check(int mid)
{
kopija = niz;
int cnt = 0;
int trd = niz[0].fi;
for(int i=0; i<m; i++)
{
if(cnt >= mid)
{
cnt = 0;
trd++;
}
if(kopija[i].fi > trd)
{
trd = kopija[i].fi;
cnt = 0;
}
else
{
cnt++;
if(trd - kopija[i].fi > d)return false;
}
kopija[i].fi = trd;
}
resenje = kopija;
return true;
}
signed main()
{
ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
int tt=1;
//cin >> tt;
while(tt--)
{
cin >> n >> d >> m;
niz.resize(m);
for(int i=0; i<m; i++)cin >> niz[i].fi, niz[i].sc = i;
sort(all(niz));
int l = 1;
int r = m;
int rez = m;
while(l<=r)
{
int mid = l + r>>1;
if(check(mid))
{
r = mid-1;
rez = mid;
}
else l = mid+1;
}
cout << rez << endl;
sort(all(resenje));
}
}
Compilation message
jobs.cpp: In function 'int main()':
jobs.cpp:64:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
64 | int mid = l + r>>1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
2896 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
13 ms |
2640 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
14 ms |
2896 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
14 ms |
2640 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
13 ms |
2640 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
13 ms |
2640 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
13 ms |
2640 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
13 ms |
2972 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
24 ms |
2788 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
21 ms |
2640 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
20 ms |
3152 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
42 ms |
5704 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
58 ms |
7560 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
81 ms |
10072 KB |
Unexpected end of file - int32 expected |
15 |
Incorrect |
107 ms |
12380 KB |
Unexpected end of file - int32 expected |
16 |
Incorrect |
120 ms |
17224 KB |
Unexpected end of file - int32 expected |
17 |
Incorrect |
143 ms |
20124 KB |
Unexpected end of file - int32 expected |
18 |
Incorrect |
175 ms |
19260 KB |
Unexpected end of file - int32 expected |
19 |
Incorrect |
200 ms |
21576 KB |
Unexpected end of file - int32 expected |
20 |
Incorrect |
151 ms |
19992 KB |
Unexpected end of file - int32 expected |