This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#define pii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
using namespace std;
const int inf = 1e18;
void solve(){
int n, k; cin >> n >> k;
string A; cin >> A;
vector<int> J(n+1), O(n+1), I(n+1);
for(int i = 0; i< n; i++){
if(A[i] == 'J')J[i+1]++;
if(A[i] == 'O')O[i+1]++;
if(A[i] == 'I')I[i+1]++;
}
for(int i = 1; i< n+1; i++){
J[i]+=J[i-1];
O[i]+=O[i-1];
I[i]+=I[i-1];
}
int ans = -1;
for(int i = 0; i< n; i++){
int p1 = lower_bound(all(J), k+J[i])-J.begin();
if(p1 == n+1)break;
int p2 = lower_bound(all(O), k+O[p1])-O.begin();
if(p2 == n+1)break;
int p3 = lower_bound(all(I), k+I[p2])-I.begin();
if(p3 == n+1)break;
ans = min((ans == -1) ? (int64_t)1e9 : ans, p3-i-3*k);
}
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
while(t--)solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |