Submission #703386

#TimeUsernameProblemLanguageResultExecution timeMemory
703386niterSelf Study (JOI22_ho_t2)C++14
0 / 100
566 ms4976 KiB
#include <bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pii pair<long long,int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define STL(i, x) for(auto &i:x) cout << i << " "; cout << "\n";
using namespace std;
 
long long a[300050], b[300050];
 
/*ostream& operator<<(ostream &os, pii XXX){
    cout << "[" << XXX.ff << ", " << XXX.ss << "]";
}*/
/*void db(){
    cout << "\n";
}
template<class T, class ...U>
void db(T XXX, U ...YYY){
    cout << XXX;  db(YYY...);
}*/
 
int main(){
    long long n, m, all;
    cin >> n >> m;
    all = n * m;
    loop(i,0,n) cin >> a[i];
    loop(i,0,n) cin >> b[i];
    long long l = 1, r = (long long)(9e18), mid;
    long long cost, classes;
    while(l != r){
        mid = (l + r + 1) >> 1;
        //db("mid = ", mid);
        classes = 0;
        loop(i,0,n){
            cost = mid;
            if(b[i] > a[i]){
                classes += ((cost-1) / b[i] + 1);
            }
            else{
                classes += min<long long>(((cost-1) / a[i] + 1), m);
                cost -= min<long long>(((cost-1) / a[i] + 1), m) * a[i];
 
                if(cost > 0)
                	classes += ((cost-1) / b[i] + 1);
            }
        }
        if(classes > n * m){
            r = mid - 1;
        }
        else{
            l = mid;
        }
    }
    cout << l << "\n";
    return 0;
}
/*
3 3
19 4 5
2 6 2
*/

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:25:21: warning: variable 'all' set but not used [-Wunused-but-set-variable]
   25 |     long long n, m, all;
      |                     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...