/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 1.277 MiB
#2 Accepted 3ms 1.277 MiB
#3 Accepted 3ms 1.102 MiB
#4 Accepted 3ms 1.098 MiB
#5 Accepted 3ms 1.324 MiB
#6 Accepted 3ms 1.285 MiB
#7 Accepted 3ms 1.09 MiB
#8 Accepted 3ms 1.23 MiB
#9 Accepted 3ms 1.148 MiB
#10 Accepted 3ms 1.324 MiB
#11 Accepted 7ms 1.352 MiB
#12 Accepted 7ms 1.355 MiB
#13 Accepted 6ms 1.355 MiB
#14 Accepted 7ms 1.359 MiB
#15 Accepted 7ms 1.355 MiB
#16 Accepted 7ms 1.312 MiB
#17 Accepted 7ms 1.27 MiB
#18 Accepted 42ms 1.703 MiB
#19 Accepted 43ms 1.703 MiB
#20 Accepted 47ms 1.699 MiB
#21 Accepted 47ms 1.484 MiB
#22 Accepted 42ms 1.699 MiB
#23 Accepted 35ms 1.703 MiB
#24 Accepted 37ms 1.699 MiB
#25 Accepted 32ms 1.633 MiB
#26 Accepted 32ms 1.695 MiB

Code

#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define endl '\n'
#define Endl '\n'

using namespace std;

const int N = 2e5 + 5;
int tc, n, k, x, a[N], pref[N];

void pre() {
    memset(pref, 0, sizeof pref);
    for (int i = 1; i <= n; i++) {
        if (a[i] % x != 0) {
            pref[i] = x - (a[i] % x);
        }
        pref[i] += pref[i - 1];
    }
}

bool isPossible(int st, int en, int move) {
    int sum = pref[en] - pref[st - 1];
    return sum <= move;
}

int maxPossible(int idx, int move) {
    int st = idx, en = n, Ans = -1;
    while (st <= en) {
        int mid = (st + en) / 2;
        if (isPossible(idx, mid, move)) {
            Ans = mid - idx + 1;
            st = mid + 1;
        } else {
            en = mid - 1;
        }
    }
    return Ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); // cout.tie(0);
    cin >> n >> k >> x;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int Ans = 0;
    for (int j = 0; j < 5; j++) {
        ++x;
        pre();

        for (int i = 1; i <= n; i++) {
            Ans = max(Ans, maxPossible(i, k));
        }
    }

    cout << Ans << endl;

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1043 Longest subarray
Contest
TLE_Headquarters - round #1
Language
C++17 (G++ 13.2.0)
Submit At
2024-03-27 17:58:04
Judged At
2024-11-11 03:37:21
Judged By
Score
100
Total Time
47ms
Peak Memory
1.703 MiB