fork(1) download
  1. #include <bits/stdc++.h>
  2. const int n = 100005;
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n, ar[200005];
  8. cin >> n;
  9. for (int i = 0; i < n; i++)
  10. cin >> ar[i];
  11.  
  12. sort(ar, ar + n);
  13. int l = 0, r = 1, c = 0;
  14. while (l <= r && r<n && l<n)
  15. {
  16. if (ar[r] - ar[l] <= 5)
  17. {
  18. cout<<"* "<<ar[l]<<" "<<ar[r]<<"\n";
  19. r++;
  20. c++;
  21. }
  22. else
  23. {
  24. cout<<"+ "<<ar[l]<<" "<<ar[r]<<"\n";
  25. l++;
  26. c = 0;
  27. }
  28. }
  29. cout << c;
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5388KB
stdin
6
1 10 17 12 15 2
stdout
* 1 2
+ 1 10
+ 2 10
* 10 10
* 10 12
* 10 15
+ 10 17
* 12 17
1