Anwar_Rizk

my code

Sep 29th, 2021 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define cin(vec) for(auto& i : vec) cin >> i
  4. #define cin_2d(vec, n, m) for(int i=0; i<n; i++) for(int j=0; j<m && cin >> vec[i][j]; j++);
  5. #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
  6. #define cout_2d(vec, r, c) for(int i=0; i<r; i++, cout << "\n") for(int j=0; j<c && cout << vec[i][j] << " "; j++);
  7. #define cout_map(mp) for(auto& [f, s] : mp) cout << f << " : " << s << "\n"
  8. #define matrix(grid, n, m) vector < vector <ll> > grid(n, vector <ll> (m));
  9. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
  10. #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  11. #define fixed(n) cout << fixed << setprecision(n)
  12. #define Num_of_Digits(n) ((int)log10(n)+1)
  13. #define getline(s) getline(cin >> ws, s)
  14. #define to_decimal(bin) stoi(bin, nullptr, 2)
  15. #define TC int t; cin >> t; while(t--)
  16. #define rall(s) s.rbegin(), s.rend()
  17. #define all(s) s.begin(), s.end()
  18. #define sz(x) int(x.size())
  19. #define Pair pair <int, int>
  20. #define fi first
  21. #define se second
  22. #define pb(x) push_back(x)
  23. #define ll long long
  24. #define PI acos(-1)
  25. #define Mod 1'000'000'007
  26. #define INF 2'000'000'000
  27. #define EPS 1e-9
  28.  
  29. void Anwar_Rizk(){
  30.   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  31.   #ifndef ONLINE_JUDGE    // Anwar Rizk 🥇🖤
  32.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  33.   #endif
  34.   Time
  35. }
  36.  
  37. struct exam{
  38.   ll task, time;
  39. };
  40.  
  41. bool comp(exam a, exam b){
  42.   if(a.time == b.time)  return a.task > b.task;
  43.   return a.time < b.time;
  44. }
  45.  
  46. int main()
  47. {   Anwar_Rizk();
  48.  
  49.     TC {
  50.       ll n, m, k, ans = 0;
  51.       cin >> n >> m >> k;
  52.       vector < exam > chef(n);
  53.       for(int i = 0; i < n; i++){
  54.         cin >> chef[i].task;
  55.       }
  56.       for(int i = 0; i < n; i++){
  57.         cin >> chef[i].time;
  58.       }
  59.       sort(all(chef), comp);
  60.       map <ll, ll> occ;
  61.       for(int i = 0; i < n; i++){
  62.         if(k >= chef[i].time) occ[chef[i].task]++, k -= chef[i].time;
  63.       }
  64.       for(auto& i : occ)  ans += ceil(i.se, 2);
  65.       for(int i = 0; i < n; i++){
  66.         cout << chef[i].task << " " << chef[i].time << "\n";
  67.       }
  68.       cout << ans << "\n";
  69.     }
  70.  
  71.   return 0;
  72. }
Add Comment
Please, Sign In to add comment