/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 832.0 KiB
#2 Accepted 2ms 840.0 KiB
#3 Accepted 2ms 836.0 KiB
#4 Accepted 2ms 836.0 KiB
#5 Accepted 2ms 832.0 KiB
#6 Accepted 2ms 1008.0 KiB
#7 Accepted 2ms 644.0 KiB
#8 Accepted 2ms 752.0 KiB
#9 Accepted 2ms 536.0 KiB
#10 Accepted 2ms 832.0 KiB
#11 Accepted 8ms 3.207 MiB
#12 Accepted 2ms 704.0 KiB
#13 Accepted 2ms 692.0 KiB
#14 Accepted 2ms 524.0 KiB
#15 Accepted 3ms 784.0 KiB
#16 Accepted 11ms 4.434 MiB
#17 Accepted 11ms 4.27 MiB
#18 Accepted 91ms 35.34 MiB
#19 Accepted 92ms 36.109 MiB
#20 Accepted 10ms 1.719 MiB
#21 Accepted 100ms 39.164 MiB
#22 Accepted 98ms 39.168 MiB
#23 Accepted 20ms 5.848 MiB
#24 Accepted 10ms 1.695 MiB
#25 Accepted 10ms 1.648 MiB
#26 Accepted 10ms 1.629 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define P(ok)            cout << (ok ? "YES\n": "NO\n")
#define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll>                   PII;
const int sz = 1e5 + 5 ;
int a[sz] ;
int preCalc[105][sz] ;
void solve()
{

     int n , K , x , Ans = 0 , flag = 1; cin >> n >> K >> x ;
     for(int i = 101 ; i > x ; i--){
         for(int j = 0 ; j < n ; j++) preCalc[i][j] = 0 ;
     }
     for(int i = 1 ; i <= n ; i++) cin >> a[i] ;
     for(int i = 101 ; i > x; i--){
         for(int j = 1 ; j <= n ; j++){
             int div = a[j] / i ;
             if(a[j] % i) div++ ;
             int nextVal = i * div ;
             preCalc[i][j] = (nextVal - a[j]) ;
         }
     }
     for(int i = 101 ; i > x ; i--){
            int cnt = 0 , sum = 0 ;
         for(int j = 1 ; j <= n ; j++) {

            if(preCalc[i][j] <= K){
                cnt++ ;
                sum += preCalc[i][j] ;
                if(sum + preCalc[i][j] > K) {
                     while(sum > K){
                        sum -= preCalc[i][j - cnt + 1] ;
                        cnt-- ;
                     }
                }
                Ans = max(Ans, cnt) ;
            }
            else {
                cnt = 0 ;
                sum = 0 ;
                continue ;
            }

         }
     }
     cout << Ans << endl ;

}
int main()
{
     __Heart__
     int t ; t = 1 ; while(t--) solve() ;
}

Information

Submit By
Type
Submission
Problem
P1043 Longest subarray
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-26 01:14:15
Judged At
2024-11-11 03:40:22
Judged By
Score
100
Total Time
100ms
Peak Memory
39.168 MiB