Advertisement
AdamTheGreat

c++ code :)

Dec 7th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. #include <set>
  6. #include <map>
  7. #include <stack>
  8. #include <queue>
  9. #include <cmath>
  10. #include <climits>
  11. #include <iomanip>
  12. #include <cassert>
  13. #include <fstream>
  14. #include <sstream>
  15. #include <unordered_map>
  16. #include <unordered_set>
  17. #include <bitset>
  18. #include <random>
  19. #include <chrono>
  20. #include <functional>
  21. #include <numeric>
  22. #include <complex>
  23. #include <array>
  24. #include <tuple>
  25. #include <valarray>
  26. #include <memory>
  27. #include <limits>
  28. #include <cctype>
  29. #include <cstring>
  30. #include <cstdio>
  31. #include <cstdlib>
  32. #include <ctime>
  33. #include <cassert>
  34. #include <climits>
  35. #include <cfloat>
  36. #include <cstdarg>
  37. #include <cstddef>
  38. #include <cstdint>
  39. #include <cwchar>
  40. #include <cwctype>
  41. #include <exception>
  42. #include <stdexcept>
  43. #include <typeinfo>
  44. #include <utility>
  45. #include <new>
  46. #include <type_traits>
  47. #include <initializer_list>
  48. #include <iterator>
  49. #include <limits>
  50. // #include <bits/stdc++.h>
  51. using namespace std;
  52.  
  53. bool pairsorterhelper(const pair<int, int> &a, const pair<int, int> &b) {
  54.     if (a.first == b.first) return a.second > b.second;
  55.     return a.first < b.first;
  56. }
  57.  
  58. int main(void) {
  59.     int n;
  60.     cin >> n;
  61.     vector<pair<int, int> > a(n);
  62.     for (int i = 0; i < n; i++) cin >> a[i].first;
  63.     for (int i = 0; i < n; i++) cin >> a[i].second;
  64.     sort(a.begin(), a.end(), pairsorterhelper);
  65.     int count = 0, index = 0;
  66.     int i = 0;
  67.     for (i = 0; i < n; i++) {
  68.         cout << a[i].first << " " << a[i].second << '\n';
  69.     }
  70.     i = 0;
  71.     cout << '\n';
  72.     cout << "------------------" << '\n';
  73.     cout << '\n';
  74.     while (index < n && i < a[n-1].first) {
  75.         ++i;
  76.         while (index < n && a[index].first < i) ++index;
  77.         if (a[index].first >= i) {
  78.             count+=a[index].second;
  79.             cout << a[index].first << " " << a[index].second << '\n';
  80.         }
  81.         ++index;
  82.     }
  83.     cout << count << '\n';
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement