Submission #766709

# Submission time Handle Problem Language Result Execution time Memory
766709 2023-06-26T05:08:41 Z raysh07 Self Study (JOI22_ho_t2) C++17
0 / 100
518 ms 8084 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#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;
    for (int i = 0; i < n; i++) a[i] = max(a[i], b[i]);
    
    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];
                continue;
            }
            
            int o = (mid + a[i] - 1) / a[i];
            int o1 = 0;
            
            if (o > m){
                o = m;
                int ex = mid - a[i] * o;
                o1 = (ex + b[i] - 1) / b[i];
            }
            
            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) 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 217 ms 8040 KB Output is correct
12 Correct 217 ms 8012 KB Output is correct
13 Correct 135 ms 8024 KB Output is correct
14 Incorrect 518 ms 8084 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 220 KB Output is correct
9 Correct 72 ms 5564 KB Output is correct
10 Correct 49 ms 3784 KB Output is correct
11 Correct 37 ms 2900 KB Output is correct
12 Correct 30 ms 2416 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Incorrect 5 ms 340 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 217 ms 8040 KB Output is correct
12 Correct 217 ms 8012 KB Output is correct
13 Correct 135 ms 8024 KB Output is correct
14 Incorrect 518 ms 8084 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 220 KB Output is correct
9 Correct 72 ms 5564 KB Output is correct
10 Correct 49 ms 3784 KB Output is correct
11 Correct 37 ms 2900 KB Output is correct
12 Correct 30 ms 2416 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Incorrect 5 ms 340 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 217 ms 8040 KB Output is correct
12 Correct 217 ms 8012 KB Output is correct
13 Correct 135 ms 8024 KB Output is correct
14 Incorrect 518 ms 8084 KB Output isn't correct
15 Halted 0 ms 0 KB -