Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <cstdio>
#include <vector>
int main(){
int n, b; scanf("%d %d\n", &n, &b);
std::vector<int> price(n);
for(int p = 0; p < n; p++){scanf("%d\n", &price[p]);}
int ans(b);
for(int u = 0; u < n; u++){
for(int v = u + 1; v < n; v++){
int candidate = b - (b / price[u]) * price[u] + (b / price[u]) * price[v];
if(candidate > ans){ans = candidate;}
}
}
printf("%d\n", ans);
return 0;
}
Copy The Code &
Try With Live Editor
Input
2 4
3 7
3 7
Output
8
Demonstration
Codeforces Solution-B. Martian Dollar-Solution in C, C++, Java, Python