#include <stdio.h>
#include <stdbool.h>
#include <algorithm>
#include <vector>
using namespace std;
int sums[302] = { 0 };
bool check(int *tab, int n, int *seq)
{
for (int i = 0; i < n; i++) sums[i] = 0;
for (int i = 0; i < n; i++)
{
for (int j = 1; j <= n; j++)
{
bool bCheck = false;
if (i - j >= 0)
{
sums[j] -= seq[i - j];
bCheck = true;
}
sums[j] += seq[i];
if (bCheck && sums[j] > tab[j-1]) return false;
}
}
return true;
}
int main()
{
int n;
scanf("%d\n",&n);
int tab[303] = { 0 };
for (int i = 0; i < n; i++)
{
scanf("%d", &tab[i]);
}
std::vector<int> vv;
vv.resize(n);
int sum = 0;
for (int i = 0; i < n; i++)
{
vv[i] = tab[i]-sum;
sum += vv[i];
//printf("%d _ ", vv[i]);
}
// 4
// 3 4 5 -1
//3 - 100 - 100 - 100 3 1 - 100 - 100 - 100 - 100 3 1 1 - 100 - 100 - 100 - 100
if (check(tab, n, &vv[0]))
{
printf("TAK\n%d\n", n);
for (int i = 0; i < n; i++)
{
if (i<n-1) printf("%d ", vv[i]);
else printf("%d\n", vv[i]);
}
}
else
printf("NIE\n");
return 0;
}
//3 4 5 - 1
//1 <=3
//2 <=4
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #include <stdio.h> #include <stdbool.h> #include <algorithm> #include <vector> using namespace std; int sums[302] = { 0 }; bool check(int *tab, int n, int *seq) { for (int i = 0; i < n; i++) sums[i] = 0; for (int i = 0; i < n; i++) { for (int j = 1; j <= n; j++) { bool bCheck = false; if (i - j >= 0) { sums[j] -= seq[i - j]; bCheck = true; } sums[j] += seq[i]; if (bCheck && sums[j] > tab[j-1]) return false; } } return true; } int main() { int n; scanf("%d\n",&n); int tab[303] = { 0 }; for (int i = 0; i < n; i++) { scanf("%d", &tab[i]); } std::vector<int> vv; vv.resize(n); int sum = 0; for (int i = 0; i < n; i++) { vv[i] = tab[i]-sum; sum += vv[i]; //printf("%d _ ", vv[i]); } // 4 // 3 4 5 -1 //3 - 100 - 100 - 100 3 1 - 100 - 100 - 100 - 100 3 1 1 - 100 - 100 - 100 - 100 if (check(tab, n, &vv[0])) { printf("TAK\n%d\n", n); for (int i = 0; i < n; i++) { if (i<n-1) printf("%d ", vv[i]); else printf("%d\n", vv[i]); } } else printf("NIE\n"); return 0; } //3 4 5 - 1 //1 <=3 //2 <=4 |
English