Derga

Untitled

Jun 11th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cmath>
  3. #include <vector>
  4. #include <string>
  5. #include <cstdint>
  6. #include <iostream>
  7. #include <set>
  8. #include <numeric>
  9. #include <queue>
  10. #include <map>
  11. #include <iomanip>
  12. #include <sstream>
  13. #include <unordered_map>
  14.  
  15. using namespace std;
  16.  
  17. typedef long long ll;
  18. typedef unsigned long long ull;
  19.  
  20. struct DayPeriodDamage {
  21. int64_t day;
  22. int64_t period;
  23. int64_t damage;
  24. };
  25.  
  26. bool operator<(const DayPeriodDamage& lhs, const DayPeriodDamage& rhs){
  27. if (lhs.day != rhs.day) return lhs.day > rhs.day;
  28. if (lhs.damage != rhs.damage) return lhs.damage < rhs.damage;
  29. return lhs.period > rhs.period;
  30. }
  31.  
  32. int main() {
  33. int t;
  34. cin >> t;
  35. while (t--) {
  36. int64_t health, attacks_count;
  37. cin >> health >> attacks_count;
  38. vector<int64_t> attacks_powers(attacks_count);
  39. for (int64_t& power : attacks_powers) cin >> power;
  40. vector<int64_t> refresh_duration(attacks_count);
  41. for (int64_t& time : refresh_duration) cin >> time;
  42.  
  43. priority_queue<DayPeriodDamage> pq;
  44. for (int i = 0; i < attacks_count; ++i) {
  45. pq.push({ 1, refresh_duration[i], attacks_powers[i] });
  46. }
  47.  
  48. while (health > 0) {
  49. auto [day, period, damage] = pq.top();
  50. pq.pop();
  51.  
  52. health -= damage;
  53. if (health <= 0) {
  54. cout << day << '\n';
  55. break;
  56. }
  57.  
  58. pq.push({ day + period, period, damage });
  59. }
  60. }
  61.  
  62. return 0;
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment