#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 (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 = 2; 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("bg%d\n", bestgain); printf("money %d\n", money); printf("bb %d\n", bestbuy);*/ if (bestgain <= 0) printf("0\n"); else printf("%d\n", bestgain - (int)(money / bestbuy) * min); } }