-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAugCkt2.cpp
More file actions
29 lines (28 loc) · 742 Bytes
/
AugCkt2.cpp
File metadata and controls
29 lines (28 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "bits/stdc++.h"
using namespace std;
long long solve(int a[], int n, int k){
multiset<int> elem[n]; long long dp[n],ans = 0;
for(int i=0;i<n;i++){
if(a[i] < k) elem[i].insert(a[i]);
for(int j =0;j<=i;j++){
if(a[i] > a[j]){
int search = k - a[i];
int pos = (lower_bound(elem[j].begin(), elem[j].end(), search));
ans += pos;
}
}
// ans += dp[i];
// cout<<a[i]<<" --> "<<dp[i]<<endl;
}
return ans ;
}
/* Driver program to test above function */
int main()
{
int n, k; cin>>n>>k;
int arr[n];
for(int i = 0;i<n;i++)
cin>>arr[i];
printf("%lld\n", solve( arr, n, k ));
return 0;
}