/* * 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 investition; int *max, *min; int * end = stockPrices.data() + days; for (int * i = stockPrices.data(); i < end;){ max = max_element (i, stockPrices.data()+ days); min = min_element (i, max); stocks = money / *min; if (*max > *min){ profit = stocks * (*max); if (profit > max_profit) { max_profit = profit; investition = stocks * (*min); } } i = max + 1; } if (max_profit == 0) cout << 0 << "\n"; else cout << (max_profit - investition) << "\n"; } return 0; }