#include<bits/stdc++.h>
using namespace std;
int n,i,j,k,x,dziel,reszta,mod,suma;
int a [310];
const long long neg=-10000000000000;
long long tab [100001];
bool dobrze;
int main ()
{
ios_base::sync_with_stdio(false);
cin>>n;
x=0;
dobrze=true;
for (i=1;i<=n;i++)
{
cin>>a[i];
dziel=a[i]/i;
reszta=a[i]%i;
if (reszta<0)
{
reszta=i+reszta;
dziel--;
//cout<<"again dziel="<<dziel<<'\n';
//cout<<"reszta="<<reszta<<'\n';
}
if (reszta==0)
{
for (j=1;j<i;j++)
{
if (dziel*j>a[j])
{
dobrze=false;
}
x++;
tab[x]=dziel;
}
x++;
tab[x]=dziel;
}
else
{
mod=i-reszta+1;
k=1;
for (j=1;j<=i;j++)
{
x++;
tab[x]=dziel+1;
if (j*mod>=k*i && j!=i)
{
k++;
tab[x]--;
}
}
suma=0;
for (j=0;j<i;j++)
{
suma+=tab[x-j];
if (suma>a[j+1])
{
dobrze=false;
}
}
}
x++;
tab[x]=neg;
}
if (dobrze==true)
{
cout<<"TAK"<<'\n';
cout<<x-1<<'\n';
for (i=1;i<x-1;i++)
{
cout<<tab[i]<<" ";
}
cout<<tab[x-1]<<'\n';
}
else
{
cout<<"NIE";
}
return 0;
}
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 76 77 78 79 80 81 82 83 84 | #include<bits/stdc++.h> using namespace std; int n,i,j,k,x,dziel,reszta,mod,suma; int a [310]; const long long neg=-10000000000000; long long tab [100001]; bool dobrze; int main () { ios_base::sync_with_stdio(false); cin>>n; x=0; dobrze=true; for (i=1;i<=n;i++) { cin>>a[i]; dziel=a[i]/i; reszta=a[i]%i; if (reszta<0) { reszta=i+reszta; dziel--; //cout<<"again dziel="<<dziel<<'\n'; //cout<<"reszta="<<reszta<<'\n'; } if (reszta==0) { for (j=1;j<i;j++) { if (dziel*j>a[j]) { dobrze=false; } x++; tab[x]=dziel; } x++; tab[x]=dziel; } else { mod=i-reszta+1; k=1; for (j=1;j<=i;j++) { x++; tab[x]=dziel+1; if (j*mod>=k*i && j!=i) { k++; tab[x]--; } } suma=0; for (j=0;j<i;j++) { suma+=tab[x-j]; if (suma>a[j+1]) { dobrze=false; } } } x++; tab[x]=neg; } if (dobrze==true) { cout<<"TAK"<<'\n'; cout<<x-1<<'\n'; for (i=1;i<x-1;i++) { cout<<tab[i]<<" "; } cout<<tab[x-1]<<'\n'; } else { cout<<"NIE"; } return 0; } |
English