#include <iostream> #include <vector> using namespace std; int main() { std::ios_base::sync_with_stdio(false); vector<long> array; int dataLength; cin >> dataLength; vector<int> givenNumbers; vector<long> sums; int tmp; cin >> tmp; sums.push_back(tmp); array.push_back(sums[0]); givenNumbers.push_back(sums[0]); for(int i = 1; i < dataLength; i ++){ int maxGiven; cin >> maxGiven; givenNumbers.push_back(maxGiven); long wantedNum = maxGiven - sums[i - 1]; long maxSum = INT64_MAX; array.push_back(wantedNum); int sumSize = sums.size(); for(int j = 0; j < sumSize ; j ++){ long sumI = sums[j]; if(sumI < maxSum){ maxSum = sumI; } sumI += wantedNum; if(j == sums.size() - 1){ sums.push_back(sumI); } sumI -= array[i - j - 1]; sums[j] = sumI; cout<<""; } if(wantedNum > maxSum){ cout<<"NIE"; return 0; } } cout<<"TAK"<<"\n"; for(auto n : array){ cout<<n<<" "; } 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 | #include <iostream> #include <vector> using namespace std; int main() { std::ios_base::sync_with_stdio(false); vector<long> array; int dataLength; cin >> dataLength; vector<int> givenNumbers; vector<long> sums; int tmp; cin >> tmp; sums.push_back(tmp); array.push_back(sums[0]); givenNumbers.push_back(sums[0]); for(int i = 1; i < dataLength; i ++){ int maxGiven; cin >> maxGiven; givenNumbers.push_back(maxGiven); long wantedNum = maxGiven - sums[i - 1]; long maxSum = INT64_MAX; array.push_back(wantedNum); int sumSize = sums.size(); for(int j = 0; j < sumSize ; j ++){ long sumI = sums[j]; if(sumI < maxSum){ maxSum = sumI; } sumI += wantedNum; if(j == sums.size() - 1){ sums.push_back(sumI); } sumI -= array[i - j - 1]; sums[j] = sumI; cout<<""; } if(wantedNum > maxSum){ cout<<"NIE"; return 0; } } cout<<"TAK"<<"\n"; for(auto n : array){ cout<<n<<" "; } return 0; } |