Pagini recente » Cod sursa (job #3247551) | Cod sursa (job #1794288) | Cod sursa (job #2820931) | Cod sursa (job #2647882) | Cod sursa (job #2079909)
#include <bits/stdc++.h>
using namespace std;
void solve() {
size_t stick_count;
cin >> stick_count;
vector< int > lengths(stick_count);
for (auto& it : lengths)
cin >> it;
sort(lengths.begin(), lengths.end());
int64_t solution = 0;
for (size_t i = 0; i < stick_count; ++i) {
for (size_t j = i + 1; j < stick_count; ++j) {
int sum = lengths[i] + lengths[j] + 1;
int left = 0, right = (int)stick_count - 1;
while (left <= right) {
int middle = (left + right) / 2;
if (lengths[middle] >= sum)
right = middle - 1;
else
left = middle + 1;
}
solution += right - (int)j;
}
}
cout << solution << endl;
}
int main() {
assert(freopen("nrtri.in", "r", stdin));
assert(freopen("nrtri.out", "w", stdout));
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
solve();
return 0;
}