#include "kanapka.h" #include "message.h" #include <algorithm> #include <iostream> #include <vector> #include <map> using namespace std; int main() { int id = MyNodeId(); if (id == 0){ long long N = GetN(); long long wholeKanapka = 0; long long leftKanapka = 0; int posL = 0; long long rightKanapka = 0; int posR = N-1; if (N == 1) cout << max(0ll, GetTaste(0)) << endl; else if (N) {// more than 1 less than 100 long long tasteLeft = 0ll; long long tasteRight = 0ll; for (int i = 0; i < N; ++i) { long long nElem = GetTaste(i); wholeKanapka += nElem; } map< pair<int, int>, long long> kanapka; tasteRight = 0; for (int i = 0; i < N; ++i) { tasteRight += GetTaste(i); tasteLeft = 0; for (int j = 0; j < N; ++j) { tasteLeft += GetTaste(N-1-j); kanapka[make_pair(i, j)] = tasteLeft + tasteRight; } } long long bestSlice = 0; for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) if ((kanapka[make_pair(i,j)] > bestSlice) and (i + j < N -1)) { bestSlice = kanapka[make_pair(i,j)]; cout << bestSlice << " " << i << " " << j << endl; } for (int i = 0; i < N; ++i) { cout << GetTaste(i) << " "; } cout << endl; cout << wholeKanapka << " " << leftKanapka << " " << rightKanapka << " " << bestSlice << endl; cout << max(0ll, max(wholeKanapka, bestSlice)) << endl; } //cout << max(max(GetTaste(0), GetTaste(N - 1)), // max(0ll, GetTaste(0) + GetTaste(N - 1))) << endl; //cout << max(0ll, GetTaste(0)) << endl; } 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 | #include "kanapka.h" #include "message.h" #include <algorithm> #include <iostream> #include <vector> #include <map> using namespace std; int main() { int id = MyNodeId(); if (id == 0){ long long N = GetN(); long long wholeKanapka = 0; long long leftKanapka = 0; int posL = 0; long long rightKanapka = 0; int posR = N-1; if (N == 1) cout << max(0ll, GetTaste(0)) << endl; else if (N) {// more than 1 less than 100 long long tasteLeft = 0ll; long long tasteRight = 0ll; for (int i = 0; i < N; ++i) { long long nElem = GetTaste(i); wholeKanapka += nElem; } map< pair<int, int>, long long> kanapka; tasteRight = 0; for (int i = 0; i < N; ++i) { tasteRight += GetTaste(i); tasteLeft = 0; for (int j = 0; j < N; ++j) { tasteLeft += GetTaste(N-1-j); kanapka[make_pair(i, j)] = tasteLeft + tasteRight; } } long long bestSlice = 0; for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) if ((kanapka[make_pair(i,j)] > bestSlice) and (i + j < N -1)) { bestSlice = kanapka[make_pair(i,j)]; cout << bestSlice << " " << i << " " << j << endl; } for (int i = 0; i < N; ++i) { cout << GetTaste(i) << " "; } cout << endl; cout << wholeKanapka << " " << leftKanapka << " " << rightKanapka << " " << bestSlice << endl; cout << max(0ll, max(wholeKanapka, bestSlice)) << endl; } //cout << max(max(GetTaste(0), GetTaste(N - 1)), // max(0ll, GetTaste(0) + GetTaste(N - 1))) << endl; //cout << max(0ll, GetTaste(0)) << endl; } return 0; } |