Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.     ios::sync_with_stdio(false);
  9.     cin.tie(0);
  10.     cout.tie(0);
  11.     long long n, ans=0;
  12.     int k, available_now=1, available=1;
  13.     cin >> n >> k;
  14.     vector<long long> printer(k);
  15.     vector<long long> status(k);
  16.     for(int i=0; i<k; i++){
  17.         cin >> printer[i];
  18.     }
  19.     sort(printer.begin(), printer.end());
  20.     while(available-1<n and available<k){
  21.         ans++;
  22.         available_now=available;
  23.         for(int i=0; i<available_now; i++){
  24.             status[i]++;
  25.             if(status[i]%printer[i]==0) available++;
  26.         }
  27.     }
  28.    
  29.     long long x=-1, y=100000000000001;
  30.     if(n<available){
  31.         x=0;
  32.         y=0;
  33.     }
  34.     long long m=(x+y)/2;
  35.     while(y-x>1){
  36.         long long copies=0;
  37.         for(int i=0; i<k; i++){
  38.             copies+=(m+status[i])/printer[i];
  39.         }
  40.         if(copies>=n){
  41.             y=m;
  42.         }else{
  43.             x=m;
  44.         }
  45.         m=(x+y)/2;
  46.     }
  47.     cout << ans+y;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement