fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int count = 0;
  6. int n,x;
  7. cin >> n >> x;
  8. int A[n];
  9. for (int i = 0; i < n; i++){
  10. cin >> A[i];
  11. }
  12. sort(A, A + n);
  13. int f = 0;
  14. int e = n -1;
  15. map<int,int> num;
  16. for (int x : A){
  17. num[x]++;
  18. }
  19. for (auto i : num){
  20. cout << i.first << "-" << i.second << endl;
  21. }
  22. while (e > f){
  23. if (A[f] + A[e] == x){
  24. count ++;
  25. // cout << A[f] << "-" << A[e] << endl;
  26. if (A[e] == A[e - 1] and e != f){
  27. e--;
  28. }
  29. else if (A[f] == A[f + 1]and f != e){
  30. f++;
  31. }
  32. else{
  33. f++;
  34. }
  35. }
  36. else if (A[f] + A[e] > x){
  37. e--;
  38. }
  39. else{
  40. f++;
  41. }
  42. }
  43. // cout << count;
  44. }
  45.  
Success #stdin #stdout 0.01s 5320KB
stdin
8 6
1 2 4 3 4 5 3 3
stdout
1-1
2-1
3-3
4-2
5-1