#include #include #include int money; int days; int prices[70000]; int bestbuy; int bestsell; int min; long long int bestgain; long long int gain; int main(void) { while(1) { scanf("%d", &days); if (days == 0) { return 0; } scanf("%d", &money); for (int i = 0; i < days; i++) scanf("%d", &(prices[i])); if (days == 1) { printf("0\n"); } else { if (prices[0] < prices[1]) { bestbuy = min = prices[0]; } else bestbuy = min = prices[1]; bestsell = prices[1]; if (prices[1] > prices[0]) { bestgain = ((int)(money / prices[0])) * prices[1]; } else bestgain = 0; gain = bestgain; for (int i = 1; i < days; i++) { if (min < bestbuy) { gain = (money / min) * prices[i]; if (gain > bestgain) { bestbuy = min; bestsell = prices[i]; bestgain = gain; } } if (min > prices[i]) { min = prices[i]; } if (bestsell < prices[i]) { bestsell = prices[i]; bestgain = (int)(money / min) * prices[i]; } } /* printf("\n\n\n"); printf("bg%d\n", bestgain); printf("money %d\n", money); printf("bb %d\n", bestbuy);*/ if (bestgain <= 0) printf("0\n"); else { long long int kusy = (long long int)(money / bestbuy); long long int outrata = kusy * bestbuy; /* printf("kusy %d\n", kusy); printf("outra %d\n", outrata); printf("min %d\n", min);*/ long long int bohatstvi = (bestgain - kusy * bestbuy);// + (money - outrata); printf("%lld\n", bohatstvi); } } } }