Need help in a problem of two pointers

Правка en1, от bovin, 2024-04-11 20:09:31

Problem

I get the error "Time limit exceeded on test 25". I can't understand why

#include <iostream>
#include <climits>

using namespace std;

int main()
{
    int a[1000];
    int n;
    long long p;
    cin >> n >> p;
    for(int i = 0; i < n; i++) cin >> a[i];
    long long amount = 0;
    int count = 0, ans_count = INT_MAX, num_track;
    int j = 0;
    for(int i = 0;  i < n; i++) {
        while(amount < p) {
            amount += a[j % n];
            j++;
            count++;
        }
        if(ans_count > count) {
            ans_count = count;
            num_track = i + 1;
        }
        amount -= a[i];
        count--;
    }
    cout << num_track << " " << ans_count;
    return 0;
}

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский bovin 2024-04-11 20:09:31 885 Initial revision (published)