---
# System prepended metadata

title: Search example

---

# Search example

```cpp=
#include<stdio.h>

int maxPrice = 0;

void search(int price[3], int weight[3], int n, int currentProduct, int currentWeight, int currentPrice) {
    if (currentProduct == 3) {
        if (currentPrice > maxPrice) {
            maxPrice = currentPrice;
        }
        return;
    }
    int weightRemain = n - currentWeight;
    for (int i = 0; i * weight[currentProduct] <= weightRemain; i++) {
        int newWeight = currentWeight + i * weight[currentProduct];
        int newPrice = currentPrice + i * price[currentProduct];
        search(price, weight, n, currentProduct + 1, newWeight, newPrice);
    }
}

int main() {
    int n;
    int weight[3];
    int price[3];
    scanf("%d", &n);
    scanf("%d%d%d%d%d%d", &price[0], &weight[0], &price[1], &weight[1], &price[2], &weight[2]);
    search(price, weight, n, 0, 0, 0);
    printf("%d\n", maxPrice);
    return 0;
}

```