이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 3e5 + 5;
const int maxN = 1e5;
const int mod = 1e9 + 7;
const ll inf = 1e18;
const int tt = 5e3 + 5;
const int base = 31;
const int lim = 100;
const int BLOCK_SIZE = 340;
const int TWO_MOD_INV = 500000004;
int dx[] = {0,-1,0,1,-1,1,-1,1};
int dy[] = {-1,0,1,0,-1,1,1,-1};
int n,m;
int a[maxn];
int d[maxn];
void Read()
{
cin >> n >> m;
for(int i = 1;i <= n;i++) cin >> a[i];
d[0] = 0;
int id = 0;
int res = 0;
for(int i = 1;i <= n;i++)
{
int k = upper_bound(d,d + id + 1,a[i]) - d;
if(k > id)
{
if(a[i] - d[id] > m)
{
res++;
d[k] = d[id] + m;
}
else d[k] = a[i];
}
else d[k] = a[i];
id = k;
}
cout << res;
}
void Solve()
{
}
void Debug()
{
}
int32_t main()
{
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int tt;
tt = 1;
// Prepare();
// cin >> tt;
for(int i = 1; i <= tt; i++)
{
Read();
Solve();
Debug();
}
}
/*
*/
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |