Untitled

mail@pastecode.io avatar
unknown
plain_text
21 days ago
663 B
1
Indexable
Never
#include <iostream>
#include <climits>
using namespace std;
typedef long long ll;
int i, j, n, k, tmp, p[1000001], o = -1, m = INT_MAX;

int main() {
    cin >> n >> k;
    for(i = 0; i < n; i++){
        cin >> tmp;
        p[i+1] = p[i] + tmp;
    }
    for(j = 1; j <= n; j++){
        for(i = j-1; i >= 0; i--){
            if(p[j] - p[i] == k){
                tmp = j - i;
                if(m > tmp){
                    o = i+1;
                    m = tmp;
                }
                break;
            }
        } 
    }
    if(o == -1) cout << 0 << endl;
    else cout << o << " " << m << endl;
    
    return 0;
}
Leave a Comment