/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 836.0 KiB
#2 Accepted 2ms 788.0 KiB
#3 Accepted 2ms 788.0 KiB
#4 Accepted 2ms 836.0 KiB
#5 Accepted 2ms 1.02 MiB
#6 Accepted 2ms 1.02 MiB
#7 Accepted 2ms 580.0 KiB
#8 Accepted 2ms 532.0 KiB
#9 Accepted 2ms 532.0 KiB
#10 Accepted 2ms 1020.0 KiB
#11 Accepted 24ms 3.16 MiB
#12 Accepted 3ms 580.0 KiB
#13 Accepted 2ms 532.0 KiB
#14 Accepted 2ms 576.0 KiB
#15 Accepted 4ms 580.0 KiB
#16 Accepted 75ms 4.445 MiB
#17 Accepted 73ms 4.402 MiB
#18 Accepted 759ms 34.961 MiB
#19 Accepted 793ms 35.723 MiB
#20 Accepted 14ms 1.184 MiB
#21 Accepted 889ms 38.781 MiB
#22 Accepted 1120ms 38.781 MiB
#23 Accepted 63ms 5.523 MiB
#24 Accepted 12ms 1.32 MiB
#25 Accepted 11ms 1.188 MiB
#26 Accepted 11ms 1.32 MiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=2e5+10,MOD=2000000007;
typedef long long ll;
int preix_sum[101][100001];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
   // cin>>t;
    while(t--){
     int n,k,x;
     cin>>n>>k>>x;
     vector<int>arr(n+1);
     for(int i=1;i<=n;i++)cin>>arr[i];
     for(int i=1;i<=n;i++){
         for(int j=x+1;j<=100;j++){
              if(arr[i]%j==0){
                preix_sum[j][i]=preix_sum[j][i-1];
              }
              else{
                int lagba=j-(arr[i]%j);
                preix_sum[j][i]=preix_sum[j][i-1]+lagba;
              }
         }
     }
     int res=0;
     for(int i=1;i<=n;i++){
        for(int j=x+1;j<=100;j++){
            int l=i,r=n;
            while(l<=r){
                int mid=l+(r-l)/2;
                int cur_sum=preix_sum[j][mid]-preix_sum[j][i-1];
                if(cur_sum<=k){
                    res=max(res,mid-i+1);
                    l=mid+1;
                }
                else r=mid-1;
            }
        }
     }
     cout<<res<<"\n";

    
   }
   return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1043 Longest subarray
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-26 13:20:33
Judged At
2024-12-17 11:30:48
Judged By
Score
100
Total Time
1120ms
Peak Memory
38.781 MiB