Advertisement
GerONSo

Untitled

Sep 18th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. int n;
  2. cin >> n;
  3. vi a(n);
  4. for(int i = 0; i < n; i++) {
  5. cin >> a[i];
  6. }
  7. vi b;
  8. for(int i = 0; i < n; i++) {
  9. for(int j = 0; j < i; j++) {
  10. b.pb(a[i] + a[j]);
  11. }
  12. }
  13. sort(all(b));
  14. for(int i = 0; i < n; i++) {
  15. int c = a[i];
  16. int pos = lower_bound(all(b), c) - b.begin();
  17. if(pos == (int)b.size() || b[pos] != c) {
  18. cout << "0\n";
  19. }
  20. else {
  21. int r = upper_bound(all(b), c) - b.begin();
  22. cout << r - pos << '\n';
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement