#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
int t[301];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> t[i];
}
int min_total[301];
for (int x = 1; x <= n; ++x) {
min_total[x] = t[x];
for (int y = x - 1; y >= 1; y--) {
min_total[x] = min(min_total[x], min_total[x - y] + t[y]);
}
}
bool ok = true;
for (int i = 1; i <= n; i++) {
if (min_total[i] < t[i]) {
ok = false;
break;
}
}
if (!ok) {
cout << "NIE" << endl;
} else {
cout << "TAK" << endl;
cout << n << endl;
t[0] = 0;
for(int i=1; i<=n; ++i) {
cout << t[i] - t[i-1] << " ";
}
cout << endl;
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #include <cstdio> #include <iostream> #include <map> #include <string> #include <vector> #include <queue> #include <stack> using namespace std; int t[301]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> t[i]; } int min_total[301]; for (int x = 1; x <= n; ++x) { min_total[x] = t[x]; for (int y = x - 1; y >= 1; y--) { min_total[x] = min(min_total[x], min_total[x - y] + t[y]); } } bool ok = true; for (int i = 1; i <= n; i++) { if (min_total[i] < t[i]) { ok = false; break; } } if (!ok) { cout << "NIE" << endl; } else { cout << "TAK" << endl; cout << n << endl; t[0] = 0; for(int i=1; i<=n; ++i) { cout << t[i] - t[i-1] << " "; } cout << endl; } } |
English