답안 #923754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923754 2024-02-07T17:31:52 Z Amr Self Study (JOI22_ho_t2) C++14
100 / 100
379 ms 12216 KB
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=3e5+7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
    ll res = 1;
    x = x; // % mod;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1) res = (res*x)  ; // % mod;
        y = y>>1;
        x = (x*x) ; // % mod;
    }
    return res;
}
ll n , m;
ll a1[N],a2[N];
pair<ll,ll> b[N];
ll cnt[N];
bool good(ll mid)
{
    memset(cnt,0,sizeof cnt);
    ll garbge = 0;
    for(int i = 1; i <= n; i++)
    {
        ll cur = b[i].S;
        ll mx = b[i].F;
        cnt[cur] += m*mx;

        if(cnt[cur]==mid) continue;
        if(cnt[cur]>mid)
        {
            ll dif = cnt[cur]-mid;
            garbge+=(dif/mx);
            cnt[cur] -= (dif/mx)*mx;
        }
        else
        {
            ll dif = mid-cnt[cur];
            ll o = ((dif+a2[cur]-1)/a2[cur]);
            garbge-=o;
            if(garbge<0) return 0;
        }
    }
    return 1;
}
void solve()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> a1[i];
    for(int i = 1; i <= n; i++) cin >> a2[i];
    for(int i = 1; i <= n; i++) {b[i].F = max(a1[i],a2[i]); b[i].S=i;}
    sort(b+1,b+1+n,greater<pair<ll,ll> >());
    ll l = 0, r = 1;
    while(good(r)) r*=2;
    //cout << good(18) << endl; return;
    while(l+1<r)
    {
        ll mid = (l+r)/2;
        if(good(mid)) l = mid; else r = mid;
    }
    cout << l << endl;
}
int main(){
    //freopen("friday.in","r",stdin);
    //freopen("friday.out","w",stdout);
    fast;
        while(TT--)
        solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9048 KB Output is correct
2 Correct 4 ms 8796 KB Output is correct
3 Correct 3 ms 8792 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 3 ms 8616 KB Output is correct
6 Correct 4 ms 8796 KB Output is correct
7 Correct 3 ms 8652 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 3 ms 8792 KB Output is correct
10 Correct 5 ms 8796 KB Output is correct
11 Correct 131 ms 12176 KB Output is correct
12 Correct 123 ms 12112 KB Output is correct
13 Correct 95 ms 12176 KB Output is correct
14 Correct 95 ms 12120 KB Output is correct
15 Correct 3 ms 8796 KB Output is correct
16 Correct 29 ms 12124 KB Output is correct
17 Correct 116 ms 11968 KB Output is correct
18 Correct 104 ms 12216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8796 KB Output is correct
2 Correct 29 ms 12124 KB Output is correct
3 Correct 116 ms 11968 KB Output is correct
4 Correct 104 ms 12216 KB Output is correct
5 Correct 3 ms 8792 KB Output is correct
6 Correct 4 ms 8796 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 4 ms 8796 KB Output is correct
9 Correct 3 ms 8796 KB Output is correct
10 Correct 4 ms 8796 KB Output is correct
11 Correct 4 ms 8796 KB Output is correct
12 Correct 4 ms 8840 KB Output is correct
13 Correct 71 ms 10844 KB Output is correct
14 Correct 49 ms 8796 KB Output is correct
15 Correct 42 ms 8792 KB Output is correct
16 Correct 33 ms 8796 KB Output is correct
17 Correct 4 ms 8796 KB Output is correct
18 Correct 5 ms 8840 KB Output is correct
19 Correct 5 ms 8796 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 5 ms 8792 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 6 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9048 KB Output is correct
2 Correct 4 ms 8796 KB Output is correct
3 Correct 3 ms 8792 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 3 ms 8616 KB Output is correct
6 Correct 4 ms 8796 KB Output is correct
7 Correct 3 ms 8652 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 3 ms 8792 KB Output is correct
10 Correct 5 ms 8796 KB Output is correct
11 Correct 131 ms 12176 KB Output is correct
12 Correct 123 ms 12112 KB Output is correct
13 Correct 95 ms 12176 KB Output is correct
14 Correct 95 ms 12120 KB Output is correct
15 Correct 3 ms 8792 KB Output is correct
16 Correct 4 ms 8796 KB Output is correct
17 Correct 3 ms 8796 KB Output is correct
18 Correct 4 ms 8796 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 4 ms 8796 KB Output is correct
21 Correct 4 ms 8796 KB Output is correct
22 Correct 4 ms 8840 KB Output is correct
23 Correct 71 ms 10844 KB Output is correct
24 Correct 49 ms 8796 KB Output is correct
25 Correct 42 ms 8792 KB Output is correct
26 Correct 33 ms 8796 KB Output is correct
27 Correct 4 ms 8796 KB Output is correct
28 Correct 5 ms 8840 KB Output is correct
29 Correct 5 ms 8796 KB Output is correct
30 Correct 3 ms 8796 KB Output is correct
31 Correct 5 ms 8792 KB Output is correct
32 Correct 2 ms 8796 KB Output is correct
33 Correct 6 ms 8796 KB Output is correct
34 Correct 3 ms 8796 KB Output is correct
35 Correct 29 ms 12124 KB Output is correct
36 Correct 116 ms 11968 KB Output is correct
37 Correct 104 ms 12216 KB Output is correct
38 Correct 4 ms 8796 KB Output is correct
39 Correct 4 ms 8844 KB Output is correct
40 Correct 4 ms 8796 KB Output is correct
41 Correct 2 ms 8796 KB Output is correct
42 Correct 4 ms 8792 KB Output is correct
43 Correct 3 ms 8796 KB Output is correct
44 Correct 3 ms 8796 KB Output is correct
45 Correct 6 ms 8796 KB Output is correct
46 Correct 8 ms 8656 KB Output is correct
47 Correct 4 ms 8796 KB Output is correct
48 Correct 28 ms 8796 KB Output is correct
49 Correct 5 ms 8796 KB Output is correct
50 Correct 5 ms 8796 KB Output is correct
51 Correct 7 ms 8796 KB Output is correct
52 Correct 6 ms 8796 KB Output is correct
53 Correct 5 ms 8840 KB Output is correct
54 Correct 5 ms 8796 KB Output is correct
55 Correct 76 ms 10832 KB Output is correct
56 Correct 35 ms 8792 KB Output is correct
57 Correct 36 ms 8656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8792 KB Output is correct
2 Correct 4 ms 8796 KB Output is correct
3 Correct 3 ms 8796 KB Output is correct
4 Correct 4 ms 8796 KB Output is correct
5 Correct 3 ms 8796 KB Output is correct
6 Correct 4 ms 8796 KB Output is correct
7 Correct 4 ms 8796 KB Output is correct
8 Correct 4 ms 8840 KB Output is correct
9 Correct 71 ms 10844 KB Output is correct
10 Correct 49 ms 8796 KB Output is correct
11 Correct 42 ms 8792 KB Output is correct
12 Correct 33 ms 8796 KB Output is correct
13 Correct 4 ms 8796 KB Output is correct
14 Correct 5 ms 8840 KB Output is correct
15 Correct 5 ms 8796 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 5 ms 8792 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 6 ms 8796 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 29 ms 12124 KB Output is correct
22 Correct 116 ms 11968 KB Output is correct
23 Correct 104 ms 12216 KB Output is correct
24 Correct 53 ms 8792 KB Output is correct
25 Correct 119 ms 10948 KB Output is correct
26 Correct 22 ms 8824 KB Output is correct
27 Correct 130 ms 12000 KB Output is correct
28 Correct 144 ms 11960 KB Output is correct
29 Correct 165 ms 12188 KB Output is correct
30 Correct 200 ms 12176 KB Output is correct
31 Correct 377 ms 12112 KB Output is correct
32 Correct 133 ms 12172 KB Output is correct
33 Correct 256 ms 12120 KB Output is correct
34 Correct 155 ms 12176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9048 KB Output is correct
2 Correct 4 ms 8796 KB Output is correct
3 Correct 3 ms 8792 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 3 ms 8616 KB Output is correct
6 Correct 4 ms 8796 KB Output is correct
7 Correct 3 ms 8652 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 3 ms 8792 KB Output is correct
10 Correct 5 ms 8796 KB Output is correct
11 Correct 131 ms 12176 KB Output is correct
12 Correct 123 ms 12112 KB Output is correct
13 Correct 95 ms 12176 KB Output is correct
14 Correct 95 ms 12120 KB Output is correct
15 Correct 3 ms 8792 KB Output is correct
16 Correct 4 ms 8796 KB Output is correct
17 Correct 3 ms 8796 KB Output is correct
18 Correct 4 ms 8796 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 4 ms 8796 KB Output is correct
21 Correct 4 ms 8796 KB Output is correct
22 Correct 4 ms 8840 KB Output is correct
23 Correct 71 ms 10844 KB Output is correct
24 Correct 49 ms 8796 KB Output is correct
25 Correct 42 ms 8792 KB Output is correct
26 Correct 33 ms 8796 KB Output is correct
27 Correct 4 ms 8796 KB Output is correct
28 Correct 5 ms 8840 KB Output is correct
29 Correct 5 ms 8796 KB Output is correct
30 Correct 3 ms 8796 KB Output is correct
31 Correct 5 ms 8792 KB Output is correct
32 Correct 2 ms 8796 KB Output is correct
33 Correct 6 ms 8796 KB Output is correct
34 Correct 4 ms 8796 KB Output is correct
35 Correct 4 ms 8844 KB Output is correct
36 Correct 4 ms 8796 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Correct 4 ms 8792 KB Output is correct
39 Correct 3 ms 8796 KB Output is correct
40 Correct 3 ms 8796 KB Output is correct
41 Correct 6 ms 8796 KB Output is correct
42 Correct 8 ms 8656 KB Output is correct
43 Correct 4 ms 8796 KB Output is correct
44 Correct 28 ms 8796 KB Output is correct
45 Correct 5 ms 8796 KB Output is correct
46 Correct 5 ms 8796 KB Output is correct
47 Correct 7 ms 8796 KB Output is correct
48 Correct 6 ms 8796 KB Output is correct
49 Correct 5 ms 8840 KB Output is correct
50 Correct 5 ms 8796 KB Output is correct
51 Correct 76 ms 10832 KB Output is correct
52 Correct 35 ms 8792 KB Output is correct
53 Correct 36 ms 8656 KB Output is correct
54 Correct 53 ms 8792 KB Output is correct
55 Correct 119 ms 10948 KB Output is correct
56 Correct 22 ms 8824 KB Output is correct
57 Correct 130 ms 12000 KB Output is correct
58 Correct 144 ms 11960 KB Output is correct
59 Correct 165 ms 12188 KB Output is correct
60 Correct 200 ms 12176 KB Output is correct
61 Correct 377 ms 12112 KB Output is correct
62 Correct 133 ms 12172 KB Output is correct
63 Correct 256 ms 12120 KB Output is correct
64 Correct 155 ms 12176 KB Output is correct
65 Correct 3 ms 8796 KB Output is correct
66 Correct 29 ms 12124 KB Output is correct
67 Correct 116 ms 11968 KB Output is correct
68 Correct 104 ms 12216 KB Output is correct
69 Correct 39 ms 8796 KB Output is correct
70 Correct 14 ms 8796 KB Output is correct
71 Correct 6 ms 8796 KB Output is correct
72 Correct 57 ms 8792 KB Output is correct
73 Correct 16 ms 8796 KB Output is correct
74 Correct 9 ms 8848 KB Output is correct
75 Correct 156 ms 12008 KB Output is correct
76 Correct 195 ms 12112 KB Output is correct
77 Correct 192 ms 11976 KB Output is correct
78 Correct 257 ms 11976 KB Output is correct
79 Correct 352 ms 12180 KB Output is correct
80 Correct 379 ms 12000 KB Output is correct
81 Correct 249 ms 12112 KB Output is correct
82 Correct 246 ms 12176 KB Output is correct