/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 540.0 KiB
#3 Accepted 1ms 540.0 KiB
#4 Accepted 1ms 484.0 KiB
#5 Accepted 1ms 540.0 KiB
#6 Accepted 1ms 488.0 KiB
#7 Accepted 1ms 540.0 KiB
#8 Accepted 1ms 572.0 KiB
#9 Accepted 1ms 540.0 KiB
#10 Accepted 1ms 552.0 KiB
#11 Accepted 8ms 712.0 KiB
#12 Accepted 2ms 540.0 KiB
#13 Accepted 2ms 536.0 KiB
#14 Accepted 2ms 624.0 KiB
#15 Accepted 2ms 544.0 KiB
#16 Accepted 12ms 720.0 KiB
#17 Accepted 12ms 716.0 KiB
#18 Accepted 102ms 2.074 MiB
#19 Accepted 105ms 2.086 MiB
#20 Accepted 9ms 2.016 MiB
#21 Accepted 113ms 2.078 MiB
#22 Accepted 112ms 2.078 MiB
#23 Accepted 21ms 2.062 MiB
#24 Accepted 9ms 2.023 MiB
#25 Accepted 9ms 2.059 MiB
#26 Accepted 9ms 2.059 MiB

Code

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vl vector<long long>
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define inv(a) for(auto &it : a) cin >> it;
#define outv(a) for(auto &it : a) cout << it << " ";cout<<"\n"
#define outv1(a) for(auto &it : a) cout << it << " "<<"\n";cout<<"\n"
#define pb push_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define INF  1e15
#define int long long 
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


int sum(vector<int>& s, int k) {
    int subarray_start = 0;
    int subarray_end = 0;
    int subarray_sum = 0;
    int max_len = -1;

    for (int i : s) {
        subarray_sum += i;
        subarray_end++;
        while (subarray_sum > k) {
            subarray_sum -= s[subarray_start];
            subarray_start++;
        }
        max_len = max(max_len, subarray_end - subarray_start);
    }

    return max_len;
}


void solve() {
    int n, k, x;
    cin >> n >> k >> x;
    vl v(n);
    inv(v);
    int ans = 0;
    for (int i = x+1; i <= 100; i++) {
        vl a(n);
        for (int j = 0; j < n; j++) {
            int dorkar = ((v[j] + i - 1) / i) * i;
            a[j] = dorkar - v[j];
        }
        // outv(a);
        ans = max(ans, sum(a,k));
    }
    cout<<ans<<endl;
}

int32_t main() {
    fastio;
    
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int T=1;
    // cin>>T;
    while (T--)
    {
        solve();
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1043 Longest subarray
Contest
TLE_Headquarters - round #1
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-27 18:17:42
Judged At
2024-03-27 18:17:42
Judged By
Score
100
Total Time
113ms
Peak Memory
2.086 MiB