#include <bits/stdc++.h>
using namespace std;
int n,w[1000],k,spe[1000],l;
long long t[100005],pre[100005];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>w[i];
for(int i=2;i<=n;i++)
for(int j=1;j<i;j++)
{
if(w[i]>w[i-j]+w[j])
{
cout<<"NIE";
return 0;
}
}
t[1]=w[1];
spe[1]++;
l++;
for(int i=2;i<=100000;i++)
{
t[i]=w[1];
pre[i-1]=pre[i-2]+t[i-1];
for(int j=2;j<=min(i,n);j++)
{
t[i]=min(t[i],w[j]-(pre[i-1]-pre[i-j]));
}
for(int j=1;j<=min(i,n);j++)
{
if(t[i]==w[j]-(pre[i-1]-pre[i-j]) && spe[j]==0)
{
spe[j]++;
l++;
}
}
k=i;
if(l==n)
{
break;
}
if(t[i]>10000000000000 || t[i]<-10000000000000)
{
cout<<"NIE";
return 0;
}
}
if(l<n)
{
cout<<"NIE";
return 0;
}
cout<<"TAK"<<endl;
cout<<k<<endl;
for(int i=1;i<=k;i++)cout<<t[i]<<" ";
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 | #include <bits/stdc++.h> using namespace std; int n,w[1000],k,spe[1000],l; long long t[100005],pre[100005]; int main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; for(int i=1;i<=n;i++) cin>>w[i]; for(int i=2;i<=n;i++) for(int j=1;j<i;j++) { if(w[i]>w[i-j]+w[j]) { cout<<"NIE"; return 0; } } t[1]=w[1]; spe[1]++; l++; for(int i=2;i<=100000;i++) { t[i]=w[1]; pre[i-1]=pre[i-2]+t[i-1]; for(int j=2;j<=min(i,n);j++) { t[i]=min(t[i],w[j]-(pre[i-1]-pre[i-j])); } for(int j=1;j<=min(i,n);j++) { if(t[i]==w[j]-(pre[i-1]-pre[i-j]) && spe[j]==0) { spe[j]++; l++; } } k=i; if(l==n) { break; } if(t[i]>10000000000000 || t[i]<-10000000000000) { cout<<"NIE"; return 0; } } if(l<n) { cout<<"NIE"; return 0; } cout<<"TAK"<<endl; cout<<k<<endl; for(int i=1;i<=k;i++)cout<<t[i]<<" "; return 0; } |
English