# Vending Machines

**URL:** <https://forum.olinfo.it/t/vending-machines/8623>\
**Category:** Aiuto\
**Created:** [24 Novembre 2023, 9:57pm UTC](https://forum.olinfo.it/t/vending-machines/8623 "2023-11-24T21:57:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AF\_zStef](https://forum.olinfo.it/user_avatar/forum.olinfo.it/af_zstef/32/1761_2.png) [@AF\_zStef](https://forum.olinfo.it/u/AF_zStef)\
**Post date:** [24 Novembre 2023, 9:57pm UTC](https://forum.olinfo.it/t/vending-machines/8623/1 "2023-11-24T21:57:44Z")

</div>

Salve, questo è il mio codice per il problema “Vending Machines”

Ho fatto 50/100 ma non mi trovo ad un problema della sub-categoria 3, nonostante io mi trovi a tutte quante (compresa quella finale, senza limitazioni)

```cpp
        // insert your code here
        bool hacker = false;
        bool run= true;
        int currency=L[0];
        if(L[0]<0){
                hacker=true;
                run=false;
        }
        if(run){
        for (int i = 1; i < Q; i++) {
            if(L[i]>0){
                currency+=L[i];
            }else{
                int index= (L[i]* -1)-1;
                if((currency-P[index])>=0){
                    currency=currency-P[index];
                }else{
                    hacker=true;
                    i=Q;
                }
            }
            }
        }

```

ci sono errori?? Grazie mille

---

<div class="post-metadata">

**Author:** ![Mazza7](https://forum.olinfo.it/user_avatar/forum.olinfo.it/mazza7/32/2689_2.png) [@Mazza7](https://forum.olinfo.it/u/Mazza7)\
**Post date:** [27 Novembre 2023, 3:38pm UTC](https://forum.olinfo.it/t/vending-machines/8623/2 "2023-11-27T15:38:39Z")

</div>

Prova con questo input:  
1  
2 4  
0 4  
-1 2 4 -2

dovrebbe dare come output OK
