206302026-01-08 11:41:08szabelrLeggyorsabb pénzkeresés (50)cpp17Elfogadva 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/012ms1004 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/22ms508 KiB
7Elfogadva2/22ms316 KiB
8Elfogadva2/23ms316 KiB
9Elfogadva2/23ms316 KiB
10Elfogadva2/22ms316 KiB
11Elfogadva2/212ms1004 KiB
12Elfogadva2/212ms776 KiB
13Elfogadva2/210ms820 KiB
14Elfogadva2/210ms820 KiB
15Elfogadva2/210ms824 KiB
16Elfogadva2/212ms820 KiB
17Elfogadva2/210ms820 KiB
18Elfogadva2/210ms1004 KiB
19Elfogadva2/210ms820 KiB
20Elfogadva2/210ms828 KiB
21Elfogadva2/210ms820 KiB
22Elfogadva2/210ms840 KiB
23Elfogadva2/210ms600 KiB
24Elfogadva2/212ms820 KiB
25Elfogadva2/210ms1012 KiB
26Elfogadva2/210ms1012 KiB
27Elfogadva2/210ms636 KiB