fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define dd double
  5. #define ld long double
  6. #define pi 3.14159265359
  7. #define ull unsigned long long
  8. #define yes cout<<"YES\n"
  9. #define no cout<<"NO\n"
  10. #define el "\n"
  11. #define Arwa ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  12. #define fix(x) cout<<fixed<<setprecision(x)
  13. ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}
  14. ll lcm(int a,int b) {return a/gcd(a,b)*b;}
  15. bool prime(ll n)
  16. {
  17. if(n==2) return true;
  18. if(n%2==0||n==1) return false;
  19. else { for(ll i=3; i*i<=n; i+=2) {if(n%i==0) return false;}}return true;
  20. }
  21. //here we go again
  22. int main()
  23. {
  24. Arwa
  25. int t=1;
  26. cin>>t;
  27. while(t--)
  28. {
  29. int n,h;
  30. vector<int>v;
  31. cin>>n>>h;
  32. int arr[n];
  33. for(int i=0;i<n;i++)
  34. arr[i]=n;
  35. for(int i=0;i<n;i++)
  36. {
  37. int l,r;
  38. cin>>l>>r;
  39. for(int k=l;k<=r;k++)
  40. arr[k-1]--;
  41. }
  42. ll sum=0,min=LONG_LONG_MAX;
  43. for(int i=0;i<n;i++)
  44. {
  45. sum=0;
  46. if(i+h<n)
  47. {
  48. for(int k=i;k<i+h;k++)
  49. sum+=arr[k];
  50. }
  51. else break;
  52. if(sum<min)
  53. min=sum;
  54. }
  55. cout<<min<<el;
  56. }
  57. return 0;
  58. }
  59. /*
  60.  
  61. */
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
0