206292026-01-08 11:40:34szabelrLeggyorsabb pénzkeresés (50)cpp17Elfogadva 50/5032ms988 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()
{
    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/01ms508 KiB
2Elfogadva0/030ms564 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/24ms440 KiB
7Elfogadva2/24ms316 KiB
8Elfogadva2/24ms316 KiB
9Elfogadva2/24ms316 KiB
10Elfogadva2/24ms436 KiB
11Elfogadva2/230ms800 KiB
12Elfogadva2/232ms564 KiB
13Elfogadva2/230ms564 KiB
14Elfogadva2/230ms564 KiB
15Elfogadva2/230ms564 KiB
16Elfogadva2/232ms564 KiB
17Elfogadva2/232ms564 KiB
18Elfogadva2/230ms756 KiB
19Elfogadva2/232ms564 KiB
20Elfogadva2/232ms564 KiB
21Elfogadva2/232ms800 KiB
22Elfogadva2/230ms756 KiB
23Elfogadva2/232ms988 KiB
24Elfogadva2/232ms564 KiB
25Elfogadva2/230ms564 KiB
26Elfogadva2/232ms564 KiB
27Elfogadva2/230ms812 KiB