Hello, I am not able to understand approach used in this problem. Some min and max thing, can someone explain in simple terms please.
On Youtube also it is not explained properly.
Hello, I am not able to understand approach used in this problem. Some min and max thing, can someone explain in simple terms please.
On Youtube also it is not explained properly.
Thanks if anyone was trying to explain me this problem. But I finally got the approach, it is all about segments… Here is my code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SIZ 1000000000
#define mod 1000000007
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
// D from 163
ll n,k;
cin >> n >> k;
ll ans = 0;
for(ll i = k - 1; i <= n; i++){
ans += ((i + 1)*(n - i)) + 1;
ans = ans%mod;
}
cout << ans << "\n";
}