# HackerEarth Milly and Chocolates IV problem solution

In this HackerEarth Milly and Chocolates IV problem solution, Milly loves to eat chocolates. She has N different chocolates. She needs to choose only one of them. At the moment, ith chocolate already has Pi pieces. The jth piece of the ith chocolate requires Tij seconds to eat. Milly knows that she will take K seconds to break one piece from any chocolate and wait for M seconds after eating any piece.

Your task is to help her in selecting chocolate that she will eat completely in the minimum possible time (including the waiting time).

## HackerEarth Milly and Chocolates IV problem solution.

`#include <iostream>#include <stdio.h>#include <cmath>#include <limits.h>#include <vector>#include <assert.h>using namespace std;int main(){    int t;    scanf("%d", &t);    while(t--) {        int n;        long long k, m;        scanf("%d%lld%lld", &n, &k, &m);        vector <int> p(n);        for (int i = 0; i < n; i++) {            scanf("%d", &p[i]);        }        long long ans_time = 1e18;        int ans_index = 1;        for (int i = 0; i < n; i++) {            long long sum = 0;            for (int j = 0; j < p[i]; j++) {                long long tij;                scanf("%lld", &tij);                sum += tij;            }            long long temp_time = k*p[i] + sum + m*(p[i]-1);            if (temp_time < ans_time) {                ans_time = temp_time;                ans_index = i + 1;            }        }        printf("%d %lld\n", ans_index, ans_time);    }}`

### Second solution

`#include<bits/stdc++.h>using namespace std;#define ll              long long int#define MOD             1000000007#define si(a)           scanf("%d", &a)#define sl(a)           scanf("%lld", &a)#define pi(a)           printf("%d", a)#define pl(a)           printf("%lld", a)#define pn              printf("\n")ll pow_mod(ll a, ll b) {    ll res = 1;    while(b) {        if(b & 1)            res = (res * a) % MOD;        a = (a * a) % MOD;        b >>= 1;    }    return res;}int p;ll T;int main() {    int t;    cin >> t;    assert(t >= 1 && t <= 10);    while(t--) {        int n, k, m;        cin >> n >> k >> m;        assert(n >= 1 && n <= 1000);        assert(k >= 1 && k <= 100000);        assert(m >= 1 && m <= 100000);        for(int i = 0; i < n; ++i) {            cin >> p[i];            assert(p[i] >= 1 && p[i] <= 100);        }        for(int i = 0; i < n; ++i) {            for(int j = 0; j < p[i]; ++j) {                cin >> T[i][j];                assert(T[i][j] >= 1 && T[i][j] <= (ll)(1e9));            }        }        ll res = LONG_LONG_MAX;        int idx = -1;        for(int i = 0; i < n; ++i) {            ll tmp = 0;            for(int j = 0; j < p[i]; ++j) {                tmp += T[i][j];                tmp += k;            }            tmp += ((p[i] - 1) * m);            if(tmp < res) {                res = tmp;                idx = i;            }        }        cout << (idx + 1) << " " << res << endl;    }    return 0;}`