/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 480.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 528.0 KiB
#4 Accepted 1ms 320.0 KiB
#5 Accepted 2ms 568.0 KiB
#6 Accepted 3ms 564.0 KiB
#7 Accepted 2ms 324.0 KiB
#8 Accepted 1ms 316.0 KiB
#9 Accepted 2ms 532.0 KiB
#10 Accepted 1ms 532.0 KiB
#11 Accepted 184ms 604.0 KiB
#12 Time Exceeded ≥2084ms ≥576.0 KiB
#13 Accepted 68ms 596.0 KiB
#14 Accepted 596ms 604.0 KiB
#15 Accepted 624ms 604.0 KiB
#16 Time Exceeded ≥2081ms ≥576.0 KiB

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];

bool isPossible(int st, int en, int move) {
    for (int i = st; i <= en; i++) {
        if (a[i] % x == 0) {
            continue;
        }
        int req = x - (a[i] % x);
        if (req > move) {
            return false;
        }
        move -= req;
    }
    return true;
}

int maxPossible(int idx, int move) {
    int st = idx, en = n - 1, 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 = 0; i < n; i++) {
        cin >> a[i];
    }

    int Ans = 0;

    for (int j = 1; j <= 10; j++) {
        ++x;
        for (int i = 0; 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:47:46
Judged At
2024-11-11 03:37:25
Judged By
Score
25
Total Time
≥2084ms
Peak Memory
≥604.0 KiB