This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set;
const int mxN = 5e5+5;
const int mod = 998244353;
const int mxlogN = 20;
const int mxK = 26;
int a[mxN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m; cin >> n >> m;
map<int, int> mp;
mp[0] = 0;
int incall = 0;
int bonus = 0;
for(int i = 0; i < n; i++)
{
cin >> a[i];
int x = a[i];
auto it = mp.lower_bound(x-m-incall);
if(it != mp.end())
{
mp[x-m-incall] = it->second-1;
auto jt = mp.lower_bound(x-m-incall);
auto pre = prev(jt);
while(jt != mp.begin() && pre->second >= jt->second)
{
mp.erase(pre);
pre = prev(jt);
}
}
incall += m;
bonus++;
}
cout << mp.begin()->second+bonus << "\n";
}
# | 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... |