mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 13:56:26 +00:00
E - Addition and Multiplication 2
https://atcoder.jp/contests/abc257/submissions/32744514
This commit is contained in:
parent
d858d4e65a
commit
fe3caadd4a
49
AtCoder/ABC257/E/E.cpp
Normal file
49
AtCoder/ABC257/E/E.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1e6 + 5;
|
||||
|
||||
int n, a[N], c[10], min, max;
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n;
|
||||
|
||||
min = 1;
|
||||
for (int i = 1; i <= 9; i++) {
|
||||
cin >> c[i];
|
||||
|
||||
if (c[i] <= c[min]) min = i;
|
||||
}
|
||||
|
||||
max = n / c[min];
|
||||
|
||||
for (int i = 1; i <= max; i++) {
|
||||
a[i] = min;
|
||||
}
|
||||
|
||||
n %= c[min];
|
||||
|
||||
for (int i = max; i; i--) {
|
||||
for (int j = 9; j > min; j--) {
|
||||
if (n >= c[j] - c[min]) {
|
||||
n -= c[j] - c[min];
|
||||
a[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = max; i; i--) {
|
||||
cout << a[i];
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user