Submission #803765

# Submission time Handle Problem Language Result Execution time Memory
803765 2023-08-03T05:54:03 Z phoenix Self Study (JOI22_ho_t2) C++17
0 / 100
1000 ms 30732 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 3e5 + 10;
const ll INF = 1e18;

ll n, m;
ll A[N], B[N];

// bool check1(ll x) {
//     vector<ll> C(n + 1);
//     vector<ll> val(n + 1);
//     for(int i = 1; i <= n; i++) {
//         C[i] = max(A[i], B[i]);
//     }
//     ll t = 0;
//     bool us[n + 1] = {};
//     while(1) {
//         int mx = -1;
//         for(int i = 1; i <= n; i++) {
//             if(us[i]) continue;
//             if(mx == -1 || (max(x - val[i], 0ll) + C[i] - 1) / C[i] < (max(x - val[mx], 0ll) + C[mx] - 1) / C[mx])
//                 mx = i; 
//         }
//         if(mx == -1) break;
//         ll k = (max(x - val[mx], 0ll) + C[mx] - 1) / C[mx];
//         t += k;
//         us[mx] = 1;
//         val[mx] += k * C[mx];
//         if(t > m) return 0;
//         int mn = -1;
//         for(int i = 1; i <= n; i++) {
//             if(us[i]) continue;
//             val[i] += k * C[i];
//             if(mn == -1 || (max(x - val[i], 0ll) + C[i] - 1) / C[i] > (max(x - val[mn], 0ll) + C[mn] - 1) / C[mn]) 
//                 mn = i;
//         }
//         if(mn != -1) C[mn] += B[mn];
//     }
//     return 1;
// }

bool check(ll x) {
    vector<ll> C(n + 1);
    vector<ll> val(n + 1), ti(n + 1);
    set<pair<ll, int>> st;
    for(int i = 1; i <= n; i++) {
        C[i] = max(A[i], B[i]);
        st.insert({ti[i] + (max(x - val[i], 0ll) + C[i] - 1) / C[i], i});
    }
    ll t = 0;
    while(!st.empty()) {
        int i = (st.begin())->second; 
        ll t = (st.begin())->first;
        if(t > m) return 0;
        val[i] += (t - ti[i]) * C[i];
        ti[i] = t;
        C[i] = 0;
        st.erase(st.begin());
        if(!st.empty()) {
            int j = (--st.end())->second;
            st.erase(--st.end());
            val[j] += (t - ti[j]) * C[j];
            ti[j] = t;
            C[j] += B[j];
            st.insert({ti[j] + (max(x - val[j], 0ll) + C[j] - 1) / C[j], j});
        }
    }
    return 1;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) 
        cin >> A[i];
    for(int i = 1; i <= n; i++) 
        cin >> B[i];
    ll l = 0, r = INF;
    while(r - l > 1) {
        ll mid = (l + r) / 2;
        if(check(mid)) l = mid;
        else r = mid;
    }
    cout << l;
}

Compilation message

Main.cpp: In function 'bool check(ll)':
Main.cpp:53:8: warning: unused variable 't' [-Wunused-variable]
   53 |     ll t = 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 1 ms 212 KB Output is correct
10 Correct 44 ms 724 KB Output is correct
11 Execution timed out 1081 ms 30732 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 1 ms 212 KB Output is correct
10 Correct 44 ms 724 KB Output is correct
11 Execution timed out 1081 ms 30732 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 1 ms 212 KB Output is correct
10 Correct 44 ms 724 KB Output is correct
11 Execution timed out 1081 ms 30732 KB Time limit exceeded
12 Halted 0 ms 0 KB -