Submission #1018601

# Submission time Handle Problem Language Result Execution time Memory
1018601 2024-07-10T07:20:16 Z vicvic Self Study (JOI22_ho_t2) C++11
0 / 100
2 ms 4700 KB
#include <iostream>
#include <fstream>
#include <climits>
#define int unsigned long long
using namespace std;
const int nmax=3e5+5;
int n, m, a[nmax], b[nmax];
bool check (int val)
{
    int days=n*m;
    for (int i=1;i<=n;i++)
    {
        int filled=0;
        if (a[i]>b[i])
        {
            int nr_act=min (days, m);
            if (LLONG_MAX/nr_act>a[i] && nr_act*a[i]<val)
            {
                days-=nr_act;
                filled=nr_act*a[i];
            }
            else
            {
                days-=val/a[i]+(val%a[i]!=0);
                continue;
            }
        }
        int nr_act=days;
        if (LLONG_MAX/nr_act>b[i] && nr_act*b[i]<val-filled)
        {
            return 0;
        }
        days-=(val-filled)/b[i]+((val-filled)%b[i]!=0);
        if (days<0)
        {
            return 0;
        }
    }
    return 1;
}
int32_t main()
{
    cin >> n >> m;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    for (int i=1;i<=n;i++)
    {
        cin >> b[i];
    }
    int st=0, dr=1e18, poz=0;
    while (st<=dr)
    {
        int mij = (st+dr) >> 1;
        if (check (mij))
        {
            st=mij+1;
            poz=mij;
        }
        else dr=mij-1;
    }
    cout << poz;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Runtime error 2 ms 4700 KB Execution killed with signal 8
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 4700 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Runtime error 2 ms 4700 KB Execution killed with signal 8
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 4700 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Runtime error 2 ms 4700 KB Execution killed with signal 8
3 Halted 0 ms 0 KB -