Submission #766723

# Submission time Handle Problem Language Result Execution time Memory
766723 2023-06-26T05:21:20 Z raysh07 Self Study (JOI22_ho_t2) C++17
0 / 100
108 ms 5028 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e15
#define f first
#define s second

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void Solve() 
{
    int n, m; cin >> n >> m;
    vector <int> a(n), b(n);
    for (auto &x : a) cin >> x;
    for (auto &x : b) cin >> x;
    
    int l = 0, r = INF;
    while (r != l){
        int mid = (l + r + 1) / 2;
        
        int use = 0, need = 0;
        for (int i = 0; i < n; i++){
            if (a[i] < b[i]) {
                need += (mid + b[i] - 1) / b[i];
                if (use + need > n * m) break;
                continue;
            }
            
            int o = (mid + a[i] - 1) / a[i];
            assert(mid - (o - 1) * a[i] > 0);
            int o1 = 0;
            
            if (o > m){
                o = m;
                int ex = mid - a[i] * o;
                o1 = (ex + b[i] - 1) / b[i];
                //assert(o1 >= 0);
                
            }
            
            int ex = a[i] * o + b[i] * o1 - mid;
            
            int sw = ex / (a[i] - b[i]);
            
            
            if (sw > o) sw = o;
            
            o -= sw;
            o1 += sw;
            use += o;
            need += o1;
            if (use + need > n * m) break;
        }
        
        if (use + need > n * m) r = mid - 1;
        else l = mid;
    }
    
    cout << l << "\n";
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
  //  cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 102 ms 4948 KB Output is correct
12 Correct 108 ms 5028 KB Output is correct
13 Correct 67 ms 5012 KB Output is correct
14 Correct 81 ms 4948 KB Output is correct
15 Runtime error 1 ms 340 KB Execution killed with signal 8
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 102 ms 4948 KB Output is correct
12 Correct 108 ms 5028 KB Output is correct
13 Correct 67 ms 5012 KB Output is correct
14 Correct 81 ms 4948 KB Output is correct
15 Runtime error 1 ms 340 KB Execution killed with signal 8
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 102 ms 4948 KB Output is correct
12 Correct 108 ms 5028 KB Output is correct
13 Correct 67 ms 5012 KB Output is correct
14 Correct 81 ms 4948 KB Output is correct
15 Runtime error 1 ms 340 KB Execution killed with signal 8
16 Halted 0 ms 0 KB -