QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#607619 | #6433. Klee in Solitary Confinement | S_zhi# | ML | 0ms | 0kb | C++14 | 1.2kb | 2024-10-03 15:34:16 | 2024-10-03 15:34:21 |
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