Untitled

mail@pastecode.io avatar
unknown
plain_text
13 days ago
697 B
2
Indexable
Never
#include <iostream>
#include <climits>

using namespace std;

int main(){
    freopen("KHLT.INP","r",stdin);
    freopen("KHLT.OUT","w",stdout);

    int n, S; cin >> n >> S;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    int ps[n+1] = {0};
    for(int i = 1; i <= n; i++){
        ps[i] = ps[i-1]+a[i-1];
    }
    int k, min = INT_MAX;
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j++){
            if(ps[j] - ps[i-1] == S){
                k = j-i+1;
                if(min > k)
                    min = k;
                break;
            }
        }
        if(min == 1) break;
    }
    cout << min << endl;

	return 0;
}
Leave a Comment