/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 316.0 KiB
#2 Accepted 1ms 320.0 KiB
#3 Accepted 1ms 324.0 KiB
#4 Accepted 1ms 320.0 KiB
#5 Accepted 2ms 768.0 KiB
#6 Accepted 2ms 320.0 KiB
#7 Accepted 1ms 548.0 KiB
#8 Accepted 1ms 320.0 KiB
#9 Accepted 1ms 532.0 KiB
#10 Accepted 2ms 436.0 KiB
#11 Accepted 46ms 716.0 KiB
#12 Accepted 3ms 628.0 KiB
#13 Accepted 3ms 576.0 KiB
#14 Accepted 3ms 552.0 KiB
#15 Accepted 6ms 532.0 KiB
#16 Accepted 68ms 720.0 KiB
#17 Accepted 67ms 724.0 KiB
#18 Accepted 701ms 2.078 MiB
#19 Accepted 729ms 2.078 MiB
#20 Accepted 16ms 2.086 MiB
#21 Accepted 783ms 2.078 MiB
#22 Accepted 727ms 2.086 MiB
#23 Accepted 100ms 2.078 MiB
#24 Accepted 16ms 2.066 MiB
#25 Accepted 16ms 2.07 MiB
#26 Accepted 16ms 2.074 MiB

Code

#include<bits/stdc++.h>
typedef long long   ll;
#define endl        '\n'
#define F           first
#define S           second
#define pb          push_back
#define yes         cout<<"YES\n"
#define no          cout<<"NO\n"
#define all(x)      x.begin(),x.end()
#define allr(x)     x.rbegin(),x.rend()
#define error1(x)   cerr<<#x<<" = "<<(x)<<endl
#define error2(a,b) cerr<<"("<<#a<<", "<<#b<<") = ("<<(a)<<", "<<(b)<<")\n";
#define coutall(v)  for(auto &it: v) cout<<it<<" "; cout<<endl;
#define _ASRafi__   ios::sync_with_stdio(false); cin.tie(0);
using namespace std;

void solve()
{
    ll n, k, x, ans = 0;
    cin >> n >> k >> x;
    vector<ll> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];        
    }
    for(int gcd = x + 1; gcd <= 100; gcd++)
    {
        vector<ll> preNeed(n);
        for(int i = 0; i < n; i++)
        {
            ll xx = (gcd - (v[i] % gcd)) % gcd;
            preNeed[i] = xx;
            if(i) preNeed[i] += preNeed[i - 1];
        }
        // cout << gcd << " => ";
        // coutall(preNeed);
        for(int i = 0; i < n; i++)
        {
            ll kk = k;
            if(i) kk += preNeed[i - 1];
            ll j = (--upper_bound(all(preNeed), kk)) - (preNeed.begin() + i);
            ans = max(ans, j + 1);
            // cout << i << " => " << j + 1 << endl;
        }
    }
    cout << ans << endl;
    return;
}

int32_t main()
{
    _ASRafi__;
    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++)
    {
        // cout << "Case " << t << ": ";
        solve();
    }
    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:55:23
Judged At
2024-11-11 03:37:22
Judged By
Score
100
Total Time
783ms
Peak Memory
2.086 MiB