Submission #254769

#TimeUsernameProblemLanguageResultExecution timeMemory
254769model_codeRoses (BOI20_roses)C++17
100 / 100
2 ms384 KiB
//Risinājums sliktākajā gadījumā strādā lineāri rožu skaitam buķetēs. #include <fstream> #include <iostream> #include <algorithm> #include <cstdio> using namespace std; template<class T> T gcd(T a, T b) { T c = a % b; while(c > 0){ a = b; b = c; c = a % b; } return b; } int main() { long long int A,B,C,D,N; //ifstream in("rozes.dat"); cin >> N >> A >> B >> C >> D ; //in.close(); if(B*C > D*A) { swap(A, C); swap(B, D); } long long ans = (N + A-1)/A*B; long long n = A/gcd(A, C); for(long long i = 1; i < n; i++) { long long t = i*D; if(N - C*i > 0) t+= (N - C*i + A-1)/A * B; ans = min(ans, t); } //ofstream out("rozes.rez"); cout<<ans<<endl; //out.close(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...