fork download
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7. int n;
  8. cin >> n;
  9. unordered_map<int, int> suma_Produktow;
  10. vector<int> kolejnosc;
  11. for (int i = 0; i < n; ++i) {
  12. int A, K;
  13. cin >> A >> K;
  14. if (suma_Produktow.find(A) == suma_Produktow.end()) {
  15. kolejnosc.push_back(A);
  16. }
  17. suma_Produktow[A] += K;
  18. }
  19. cout << kolejnosc.size() << "\n";
  20. for (int a : kolejnosc) {
  21. cout << a << " " << suma_Produktow[a] << "\n";
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5292KB
stdin
6
2 1
3 11
1 4
3 2
7 1
2 1
stdout
4
2 2
3 13
1 4
7 1