Submission #789043

# Submission time Handle Problem Language Result Execution time Memory
789043 2023-07-20T22:07:03 Z stefanneagu Self Study (JOI22_ho_t2) C++17
62 / 100
1000 ms 22632 KB
#include <iostream>
#include <set>
#include <algorithm>
 
using namespace std;
 
const int nmax = 3e5 + 7;
 
int v[nmax], b[nmax], cnt[nmax], n, k;
long long unu = 1;

struct pairing {
    long long first;
    int second;
    const bool operator < (pairing a) const {
        if(first != a.first) {
            return first < a.first;
        } else {
            return second > a.second;
        }
    }
};
 
bool check(long long x) {
    long long sum = 0;
    for(int i = 1; i <= n; i ++) {
        long long curr = x / v[i];
        if(v[i] * curr < x) {
            curr ++;
        }
        sum += curr;
    }
    if(sum <= n * k) {
        return 1;
    }
    return 0;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    int test = 1;
    cin >> n >> k;
    for(int i = 1; i <= n; i ++) {
        cin >> v[i];
    } 
    for(int i = 1; i <= n; i ++){
        cin >> b[i];
        if(v[i] != b[i]) {
            test = 1;
        }
    }
    if(!test) {
        long long l = 0, r = 1e18;
        int opr = 0;
        while(l < r) {
            opr ++;
            long long mid = (l + r) / 2;
            if(check(mid) == 1) {
                l = mid + 1;
            } else {
                r = mid - 1;
            }
            if(opr == 100) {
                break;
            }
        }
        cout << max(unu, r);
        return 0;
    }
    set<pairing> pq;
    for(int i = 1; i <= n; i ++) {
        pq.insert({max(v[i], b[i]), i});
        cnt[i] = 1;
    }
    for(int i = 2; i <= k; i ++) {
        for(int j = 1; j <= n; j ++) {
            pairing curr = *(pq.begin());
            long long sum = curr.first;
            int ind = curr.second;
            pq.erase({sum, ind});
            if(cnt[ind] < k) {
                sum += max(v[ind], b[ind]);
                cnt[ind] ++;
            } else {
                sum +=  b[ind];
            }
            pq.insert({sum, ind});
        }
    } 
    long long minn = 1e18;
    for(auto it : pq) {
        // cout << it.first << " " << it.second << endl;
        minn = min(minn, it.first);
    }
    cout << minn;
    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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 189 ms 22608 KB Output is correct
12 Correct 188 ms 22548 KB Output is correct
13 Correct 98 ms 22524 KB Output is correct
14 Correct 100 ms 22604 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 86 ms 22592 KB Output is correct
17 Correct 110 ms 22524 KB Output is correct
18 Correct 187 ms 22632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 86 ms 22592 KB Output is correct
3 Correct 110 ms 22524 KB Output is correct
4 Correct 187 ms 22632 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 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 99 ms 11340 KB Output is correct
14 Correct 76 ms 7740 KB Output is correct
15 Correct 54 ms 5828 KB Output is correct
16 Correct 79 ms 4756 KB Output is correct
17 Correct 27 ms 340 KB Output is correct
18 Correct 21 ms 332 KB Output is correct
19 Correct 18 ms 336 KB Output is correct
20 Correct 10 ms 332 KB Output is correct
21 Correct 10 ms 212 KB Output is correct
22 Correct 42 ms 596 KB Output is correct
23 Correct 43 ms 596 KB Output is correct
# 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 189 ms 22608 KB Output is correct
12 Correct 188 ms 22548 KB Output is correct
13 Correct 98 ms 22524 KB Output is correct
14 Correct 100 ms 22604 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 99 ms 11340 KB Output is correct
24 Correct 76 ms 7740 KB Output is correct
25 Correct 54 ms 5828 KB Output is correct
26 Correct 79 ms 4756 KB Output is correct
27 Correct 27 ms 340 KB Output is correct
28 Correct 21 ms 332 KB Output is correct
29 Correct 18 ms 336 KB Output is correct
30 Correct 10 ms 332 KB Output is correct
31 Correct 10 ms 212 KB Output is correct
32 Correct 42 ms 596 KB Output is correct
33 Correct 43 ms 596 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 86 ms 22592 KB Output is correct
36 Correct 110 ms 22524 KB Output is correct
37 Correct 187 ms 22632 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 36 ms 696 KB Output is correct
46 Correct 6 ms 1012 KB Output is correct
47 Correct 7 ms 340 KB Output is correct
48 Correct 31 ms 4128 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 34 ms 340 KB Output is correct
51 Correct 46 ms 596 KB Output is correct
52 Correct 10 ms 340 KB Output is correct
53 Correct 25 ms 212 KB Output is correct
54 Correct 29 ms 340 KB Output is correct
55 Correct 119 ms 11360 KB Output is correct
56 Correct 76 ms 7752 KB Output is correct
57 Correct 75 ms 7764 KB Output is correct
# 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 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 99 ms 11340 KB Output is correct
10 Correct 76 ms 7740 KB Output is correct
11 Correct 54 ms 5828 KB Output is correct
12 Correct 79 ms 4756 KB Output is correct
13 Correct 27 ms 340 KB Output is correct
14 Correct 21 ms 332 KB Output is correct
15 Correct 18 ms 336 KB Output is correct
16 Correct 10 ms 332 KB Output is correct
17 Correct 10 ms 212 KB Output is correct
18 Correct 42 ms 596 KB Output is correct
19 Correct 43 ms 596 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 86 ms 22592 KB Output is correct
22 Correct 110 ms 22524 KB Output is correct
23 Correct 187 ms 22632 KB Output is correct
24 Execution timed out 1075 ms 3696 KB Time limit exceeded
25 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 189 ms 22608 KB Output is correct
12 Correct 188 ms 22548 KB Output is correct
13 Correct 98 ms 22524 KB Output is correct
14 Correct 100 ms 22604 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 99 ms 11340 KB Output is correct
24 Correct 76 ms 7740 KB Output is correct
25 Correct 54 ms 5828 KB Output is correct
26 Correct 79 ms 4756 KB Output is correct
27 Correct 27 ms 340 KB Output is correct
28 Correct 21 ms 332 KB Output is correct
29 Correct 18 ms 336 KB Output is correct
30 Correct 10 ms 332 KB Output is correct
31 Correct 10 ms 212 KB Output is correct
32 Correct 42 ms 596 KB Output is correct
33 Correct 43 ms 596 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 36 ms 696 KB Output is correct
42 Correct 6 ms 1012 KB Output is correct
43 Correct 7 ms 340 KB Output is correct
44 Correct 31 ms 4128 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 34 ms 340 KB Output is correct
47 Correct 46 ms 596 KB Output is correct
48 Correct 10 ms 340 KB Output is correct
49 Correct 25 ms 212 KB Output is correct
50 Correct 29 ms 340 KB Output is correct
51 Correct 119 ms 11360 KB Output is correct
52 Correct 76 ms 7752 KB Output is correct
53 Correct 75 ms 7764 KB Output is correct
54 Execution timed out 1075 ms 3696 KB Time limit exceeded
55 Halted 0 ms 0 KB -