206302026-01-08 11:41:08szabelrLeggyorsabb pénzkeresés (50)cpp17Accepted 50/5012ms1012 KiB
// Leggyorsabb pénzkeresés.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, target;
    cin >> n >> target;
    vector<int>profits(n);
    for (int i = 0; i < n; i++)
    {
        int x; cin >> x;
        profits[i] = x;
    }
    int i = 0;
    int best_size = INT_MAX;
    long long cur_sum = 0;
    for (int j = 0; j < n; j++)
    {
        cur_sum += profits[j];
        while (cur_sum >= target and i<=j)
        {
            best_size = min(best_size, j - i + 1);
            cur_sum -= profits[i];
            
            i++;
        }
    }
   
    cout << best_size;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/012ms1004 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/22ms508 KiB
7Accepted2/22ms316 KiB
8Accepted2/23ms316 KiB
9Accepted2/23ms316 KiB
10Accepted2/22ms316 KiB
11Accepted2/212ms1004 KiB
12Accepted2/212ms776 KiB
13Accepted2/210ms820 KiB
14Accepted2/210ms820 KiB
15Accepted2/210ms824 KiB
16Accepted2/212ms820 KiB
17Accepted2/210ms820 KiB
18Accepted2/210ms1004 KiB
19Accepted2/210ms820 KiB
20Accepted2/210ms828 KiB
21Accepted2/210ms820 KiB
22Accepted2/210ms840 KiB
23Accepted2/210ms600 KiB
24Accepted2/212ms820 KiB
25Accepted2/210ms1012 KiB
26Accepted2/210ms1012 KiB
27Accepted2/210ms636 KiB