Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef unsigned long long int ulli;
  5. struct dragon{
  6.     ulli days, bills;
  7.     int arrival_day;
  8.     int training_day;
  9. };
  10.  
  11. const bool operator < (const dragon a, const dragon b) {
  12.     return a.bills*b.days < a.days*b.bills;
  13. }
  14.  
  15. int main()
  16. {    
  17.     priority_queue <dragon> dragons;
  18.     unsigned long long int ans=0;
  19.     unsigned long long int d,b;
  20.     scanf("%llu %llu",&d,&b);
  21.     dragon current_dragon;
  22.     current_dragon.days=d;
  23.     current_dragon.bills=b;
  24.     current_dragon.arrival_day=0;
  25.     current_dragon.training_day=0;
  26.     int current_day=0;
  27.     current_day++;
  28.     while(scanf("%llu %llu",&d,&b)!=EOF){
  29.         dragon a;
  30.         a.days = d;
  31.         a.bills = b;
  32.         a.arrival_day = current_day;
  33.         dragons.push(a);
  34.         if(current_day - current_dragon.training_day == current_dragon.days){
  35.             current_dragon = dragons.top();
  36.             dragons.pop();        
  37.             current_dragon.training_day = current_day;
  38.             ans += (current_dragon.training_day-current_dragon.arrival_day)*(current_dragon.bills);
  39.         }
  40.         current_day++;
  41.     }
  42.     while(!dragons.empty()){
  43.         if(current_day - current_dragon.training_day == current_dragon.days){
  44.             current_dragon = dragons.top();
  45.             dragons.pop();        
  46.             current_dragon.training_day = current_day;
  47.             ans += (current_dragon.training_day-current_dragon.arrival_day)*(current_dragon.bills);
  48.         }
  49.         current_day++;
  50.     }
  51.     printf("%llu\n",ans);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement