QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607619#6433. Klee in Solitary ConfinementS_zhi#ML 0ms0kbC++141.2kb2024-10-03 15:34:162024-10-03 15:34:21

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 15:34:21]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2024-10-03 15:34:16]
  • 提交

answer

#include <iostream>
#include <vector> 
#include <map>
using namespace std ; 
int solve(vector<int> q  ){
    int final_ans = 0; 
    int sum = 0 , sz = q.size(); 
    for(int i = 0 ; i < sz ; i ++){
      if(q[i] == -1) sum ++ ;  
    }
    int s[sz + 1] ; 
    for(int i = 0 ; i < sz ; i ++ ){
        if(i == 0) s[0] = q[0] ; 
        else s[i] = s[i - 1] + q[i] ;   
    }
    int minn[sz + 1] ; 
    for(int i = 0 ; i < sz ; i ++ ){
        if(i == 0 ) minn[i] = 0 ; 
        else minn[i] = min(minn[i-1] , s[i]) ; 
        // cout << minn[i] << ' ' <<
        
        final_ans = max(final_ans , sum + s[i] - minn[i]) ;        
    }
    
    return final_ans ; 
}
int main(){
    map<int , vector<int> > q ; 
    int n , k ; cin >> n >> k ;
    vector <int> a(n) ; 
    for(int i = 0 ; i < n ; i ++ ){
        cin >> a[i] ; 
        q[a[i]].push_back(-1) ; 
        q[a[i] + k].push_back(1) ; 
        // 1 是正主 ,  2 还要转化  
    }
    int ans = 0 ;  
    for(int i = -2e6 ; i <= 2e6 ; i ++ ){
        // if(q[i].size()) cout << q[i].size() << endl; 
       ans = max(solve(q[i] ) , ans) ; 
    }
    cout << ans << endl ; 

    return 0 ; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

input:

5 2
2 2 4 4 4

output:

5

result: