Help required in CF EDU two pointers topic

I am solving the above problem on codeforces. I am unable to figure out my mistake (Current solution verdict is WA) . Basically I have used 2 pointer approach and I will remove elements from left if difference is greater than K, else I will continue to add it from the right side.

#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define deb(x) cout<<#x<<":= "<<x<<"\n";
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef long double ld;

void solve()
   // write your logic here
   int n; ll k;
   cin >> n >> k;
   std::vector<int> a(n);
   for (int i = 0; i < n; i++) cin >> a[i];
   int l = 0, r = 0;
   map<int, int> mp;
   ll cnt = 0;
   while (r < n)
      int min = (*mp.begin()).first, max = (*mp.rbegin()).first;
      while (max - min > k)
         if (mp[a[l]] > 1) mp[a[l]]--;
         else mp.erase(a[l]);
         min = (*mp.begin()).first;
         max = (*mp.rbegin()).first;
      cnt += (r - l + 1);
   cout << cnt << "\n";

int main()
   int t = 1;  //cin >> t;
   while (t--)
   return 0;

Please help me to figure out what I am missing in this solution.

use long long in vector, map and few other variables because array element can be up to 1e18

1 Like

Thanks. I didn’t notice that ai<=10^18.