#include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<int> a(n),r(n),s(n),b(n,-1000000000); for (int i=0;i<n;i++) cin >> a[i]; b[0]=s[0]=r[0]=a[0]; for (int i=1;i<n;i++) { s[i]=r[i]=a[i]-a[i-1]; if (s[i]>b[0]) b[0]=s[i]; } for (int i=1;i<n;i++) { for (int j=n-1;j>=i;j--) { s[j]=s[j-1]+r[j]; if (s[j]>b[i]) b[i]=s[j]; } // for (int j=i;j<n;j++) // cout << s[j] << " " ; // cout << endl; } // for (int i=0;i<n;i++) cout << b[i] << " "; cout << endl; bool ok = true; for (int i=0;ok && i<n;i++) ok = a[i]==b[i]; if (!ok) cout << "NIE"; else { cout << "TAK" << endl; cout << n << endl; for (int i=0;i<n;i++) cout << r[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 | #include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<int> a(n),r(n),s(n),b(n,-1000000000); for (int i=0;i<n;i++) cin >> a[i]; b[0]=s[0]=r[0]=a[0]; for (int i=1;i<n;i++) { s[i]=r[i]=a[i]-a[i-1]; if (s[i]>b[0]) b[0]=s[i]; } for (int i=1;i<n;i++) { for (int j=n-1;j>=i;j--) { s[j]=s[j-1]+r[j]; if (s[j]>b[i]) b[i]=s[j]; } // for (int j=i;j<n;j++) // cout << s[j] << " " ; // cout << endl; } // for (int i=0;i<n;i++) cout << b[i] << " "; cout << endl; bool ok = true; for (int i=0;ok && i<n;i++) ok = a[i]==b[i]; if (!ok) cout << "NIE"; else { cout << "TAK" << endl; cout << n << endl; for (int i=0;i<n;i++) cout << r[i] << " "; } return 0; } |