fork(2) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. inline int power(int a, int b) {
  6. int x = 1;
  7. while (b) {
  8. if (b & 1) x *= a;
  9. a *= a;
  10. b >>= 1;
  11. }
  12. return x;
  13. }
  14.  
  15.  
  16. const int M = 1000000007;
  17. const int N = 3e5+9;
  18. const int INF = 2e9+1;
  19. const int LINF = 2000000000000000001;
  20.  
  21. //_ ***************************** START Below *******************************
  22.  
  23.  
  24.  
  25. vector<int> a;
  26. void consistency(int n, int k) {
  27.  
  28. int s= 0, e = n-1;
  29. int ans = 0;
  30. while(s<=e){
  31. int sum = a[s] + a[e];
  32. if(sum > k){
  33. ans += (e-s);
  34. e--;
  35. }
  36. else{
  37. s++;
  38. }
  39. }
  40.  
  41. cout << ans << endl;
  42.  
  43. }
  44.  
  45.  
  46. void solve() {
  47.  
  48. int n, k;
  49. cin >> n >> k;
  50.  
  51. a.resize(n);
  52.  
  53. for(int i=0; i<n; i++) cin >> a[i];
  54.  
  55. consistency(n, k);
  56.  
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63. int32_t main() {
  64. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  65.  
  66. int t = 1;
  67. // cin >> t;
  68. while (t--) {
  69. solve();
  70. }
  71.  
  72. return 0;
  73. }
Success #stdin #stdout 0.01s 5320KB
stdin
5 8
1 2 7 9 10 
stdout
8