Skip to content

Instantly share code, notes, and snippets.

@Tdrj2716
Last active March 13, 2020 01:39
Show Gist options
  • Save Tdrj2716/c0c66f51c54803bf35bd885e1e318686 to your computer and use it in GitHub Desktop.
Save Tdrj2716/c0c66f51c54803bf35bd885e1e318686 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
vector<int> a, b, c;
int n, inp;
long long int ans = 0;
cin >> n;
for(int i = 0; i < n; i++){
cin >> inp;
a.push_back(inp);
}
sort(a.begin(), a.end());
for(int i = 0; i < n; i++){
cin >> inp;
b.push_back(inp);
}
sort(b.begin(), b.end());
for(int i = 0; i < n; i++){
cin >> inp;
c.push_back(inp);
}
sort(c.begin(), c.end());
for(int i = 0; i < n; i++){
long long int ai = distance(a.begin(), lower_bound(a.begin(), a.end(), b[i]));
long long int ci = distance(upper_bound(c.begin(), c.end(), b[i]), c.end());
ans += ai * ci;
}
cout << ans << endl;
return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int n, li, ans = 0;
cin >> n;
vector<int> l;
for(int i = 0; i < n; i++){
cin >> li;
l.push_back(li);
}
sort(l.begin(), l.end());
for(int m1 = n - 1; m1 >= 2; m1--){
for(int m2 = m1 - 1; m2 >= 1; m2--){
ans += distance(upper_bound(l.begin(), l.begin() + m2, l[m1] - l[m2]), l.begin() + m2);
}
}
cout << ans << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment