/* * ss.cpp * * Copyright 2009 Contest team 23 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ #include #include #include using namespace std; int main(int argc, char** argv) { int days; int money; vector stockPrices(70001); while (true){ cin >> days; if (days == 0) break; cin >> money; // load cen for (int i = 0; i < days; i++){ cin >> stockPrices[i]; } // najiti nejvyhodnejsi :partie: int max_profit = 0; int profit = 0; int stocks; int maxval; int investition; for (int i = 0; i < days-1; i++){ stocks = money / stockPrices[i]; maxval = *max_element(stockPrices.data()+i+1, stockPrices.data()+ days); if (maxval > stockPrices[i]){ profit = stocks * maxval; if (profit > max_profit) { max_profit = profit; investition = stocks * stockPrices[i]; } } } if (max_profit == 0) cout << 0 << "\n"; else cout << (max_profit - investition) << "\n"; } return 0; }