Submission #703593

#TimeUsernameProblemLanguageResultExecution timeMemory
703593niterSelf Study (JOI22_ho_t2)C++14
62 / 100
100 ms5040 KiB
#include <iostream>
#include <vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
long long A[300050], B[300050];

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int N, M;
    cin >> N >> M;
    loop(i,0,N) cin >> A[i];
    loop(i,0,N) cin >> B[i];
    loop(i,0,N) A[i] = max(A[i], B[i]);

    long long ok = 0, ng = 1LL << 60;
    auto check = [&](long long x) -> bool {
        long long day = 0, cost;
        loop(i,0,N){
            cost = x;
            if(x <= A[i] * M) day += (x + A[i] - 1) / A[i];
            else day += M + (x - A[i] * M + B[i] - 1) / B[i];
//            day += min<long long>(((cost-1) / A[i] + 1), M);
//            cost -= min<long long>(((cost-1) / A[i] + 1), M) * A[i];
//            if(cost > 0)
//                day += ((cost-1) / B[i] + 1);
            if(day > N * M) return 0;
        }
        return 1;
    };
    while(ng >= ok + 2){
        long long mid = (ng + ok) / 2;
        if(check(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}

Compilation message (stderr)

Main.cpp: In lambda function:
Main.cpp:17:28: warning: variable 'cost' set but not used [-Wunused-but-set-variable]
   17 |         long long day = 0, cost;
      |                            ^~~~
#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...