/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 11ms 328.0 KiB
#2 Accepted 11ms 552.0 KiB
#3 Accepted 11ms 556.0 KiB
#4 Accepted 11ms 328.0 KiB
#5 Accepted 11ms 556.0 KiB
#6 Accepted 11ms 328.0 KiB
#7 Accepted 11ms 560.0 KiB
#8 Accepted 12ms 564.0 KiB
#9 Accepted 11ms 560.0 KiB
#10 Accepted 12ms 540.0 KiB
#11 Accepted 11ms 556.0 KiB

Code

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
using namespace std;

void solve(int cs) {
  int x, a, b, c, n;
  cin >> x >> a >> b >> c >> n;
  n -= x;
  if (n <= 0) {
    cout << "NO\n";
    return;
  }
  int res = 1e9;
  for (int i = 0; i <= 200; i++) {
    for (int j = 0; j <= 200; j++) {
      for (int k = 0; k <= 200; k++) {
        int now = i * a + j * b + k * c;
        if (now == n) {
          res = min(res, i + j + k);
        }
      }
    }
  }
  if (res == 1e9) cout << "NO\n";
  else {
    cout << "YES\n";
    cout << res << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  // cin >> tc;
  for (int cs = 1; cs <= tc; cs++) {
    solve(cs);
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1028 Magical box and spell
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-11 03:07:57
Judged At
2024-11-11 03:27:49
Judged By
Score
100
Total Time
12ms
Peak Memory
564.0 KiB