Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using namespace std;
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- long long n, ans=0;
- int k, available_now=1, available=1;
- cin >> n >> k;
- vector<long long> printer(k);
- vector<long long> status(k);
- for(int i=0; i<k; i++){
- cin >> printer[i];
- }
- sort(printer.begin(), printer.end());
- while(available-1<n and available<k){
- ans++;
- available_now=available;
- for(int i=0; i<available_now; i++){
- status[i]++;
- if(status[i]%printer[i]==0) available++;
- }
- }
- long long x=-1, y=100000000000001;
- if(n<available){
- x=0;
- y=0;
- }
- long long m=(x+y)/2;
- while(y-x>1){
- long long copies=0;
- for(int i=0; i<k; i++){
- copies+=(m+status[i])/printer[i];
- }
- if(copies>=n){
- y=m;
- }else{
- x=m;
- }
- m=(x+y)/2;
- }
- cout << ans+y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement