#include <iostream>
#include <algorithm>
using namespace std;
int n;
long long t[300];
long long w[300];
bool waliduj() {
long long s = 0;
long long v = 0;
for(int i = 1;i<=n;i++){
s += w[i-1];
v = s;
if(v>t[i-1])return false;
for(int j = i;j<n;j++){
v-=w[j-i];
v+=w[j];
if(v>t[i-1])return false;
}
}
return true;
}
int main () {
cin>>n;
for(int i=0;i<n;i++){
cin>>t[i];
}
n = 6;
/* for( int h = 12; h<1000000;h++){
for(int i=0;i<6;i++){
w[i]=0;
}
int d = 0;
int H = h;
while(H>0){
w[d]=H%10-5;
H/=10;
d++;
}
cout<<"W: ";
for(int i=0;i<6;i++)
cout<<w[i]<<" ";
cout<<"\n";/
t[0]=w[0];
for(int i=1;i<6;i++)
t[0]=max(t[0],w[i]);
t[1]=w[0]+w[1];
long long s = t[1];
for(int i=2;i<6;i++) {
s-=w[i-2];
s+=w[i];
t[1]= max(t[1],s);
}
t[2]=w[0]+w[1]+w[2];
s = t[2];
for(int i=3;i<6;i++) {
s-=w[i-3];
s+=w[i];
t[2]= max(t[2],s);
}
t[3]=w[0]+w[1]+w[2]+w[3];
s = t[3];
for(int i=4;i<6;i++) {
s-=w[i-4];
s+=w[i];
t[3]= max(t[3],s);
}
t[4]=w[0]+w[1]+w[2]+w[3]+w[4];
s = t[4];
for(int i=5;i<6;i++) {
s-=w[i-5];
s+=w[i];
t[4]= max(t[4],s);
}
t[5]=w[0]+w[1]+w[2]+w[3]+w[4]+w[5];
/*cout<<"T: ";
for(int i=0;i<6;i++)
cout<<t[i]<<" ";
cout<<"\n";*/
w[0]=t[0];
for(int i=1;i<n;i++){
w[i]=t[i]-t[i-1];
}
/*cout<<"W: ";
for(int i=0;i<6;i++)
cout<<w[i]<<" ";
cout<<"\n";*/
if(waliduj()){
cout<<"TAK\n";
cout<<n<<"\n";
for(int i=0;i<n;i++){
cout<<w[i]<<" ";
}
}else{
// cout<<h<<"\n";
cout<<"NIE\n";
//int g;cin>>g;
}
//
//}
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | #include <iostream> #include <algorithm> using namespace std; int n; long long t[300]; long long w[300]; bool waliduj() { long long s = 0; long long v = 0; for(int i = 1;i<=n;i++){ s += w[i-1]; v = s; if(v>t[i-1])return false; for(int j = i;j<n;j++){ v-=w[j-i]; v+=w[j]; if(v>t[i-1])return false; } } return true; } int main () { cin>>n; for(int i=0;i<n;i++){ cin>>t[i]; } n = 6; /* for( int h = 12; h<1000000;h++){ for(int i=0;i<6;i++){ w[i]=0; } int d = 0; int H = h; while(H>0){ w[d]=H%10-5; H/=10; d++; } cout<<"W: "; for(int i=0;i<6;i++) cout<<w[i]<<" "; cout<<"\n";/ t[0]=w[0]; for(int i=1;i<6;i++) t[0]=max(t[0],w[i]); t[1]=w[0]+w[1]; long long s = t[1]; for(int i=2;i<6;i++) { s-=w[i-2]; s+=w[i]; t[1]= max(t[1],s); } t[2]=w[0]+w[1]+w[2]; s = t[2]; for(int i=3;i<6;i++) { s-=w[i-3]; s+=w[i]; t[2]= max(t[2],s); } t[3]=w[0]+w[1]+w[2]+w[3]; s = t[3]; for(int i=4;i<6;i++) { s-=w[i-4]; s+=w[i]; t[3]= max(t[3],s); } t[4]=w[0]+w[1]+w[2]+w[3]+w[4]; s = t[4]; for(int i=5;i<6;i++) { s-=w[i-5]; s+=w[i]; t[4]= max(t[4],s); } t[5]=w[0]+w[1]+w[2]+w[3]+w[4]+w[5]; /*cout<<"T: "; for(int i=0;i<6;i++) cout<<t[i]<<" "; cout<<"\n";*/ w[0]=t[0]; for(int i=1;i<n;i++){ w[i]=t[i]-t[i-1]; } /*cout<<"W: "; for(int i=0;i<6;i++) cout<<w[i]<<" "; cout<<"\n";*/ if(waliduj()){ cout<<"TAK\n"; cout<<n<<"\n"; for(int i=0;i<n;i++){ cout<<w[i]<<" "; } }else{ // cout<<h<<"\n"; cout<<"NIE\n"; //int g;cin>>g; } // //} return 0; } |
English