/** * @param nums: A list of integers * @return: An integer denotes the sum of max two non-overlapping subarrays */ int maxTwoSubArrays(vector<int> nums) { int len = nums.size(); if (len == 0) { return 0; } vector<int>LTR(len, 0); vector<int>RTL(len, 0); int sumL = 0; int sumR = 0; int maxSumL = INT_MIN; int maxSumR = INT_MIN; for (int i = 0; i < len; i++) { if (sumL < 0) { sumL = 0; } sumL += nums[i]; maxSumL = max(maxSumL, sumL); LTR[i] = maxSumL; if (sumR < 0) { sumR = 0; } sumR += nums[len - 1 -i]; maxSumR = max(maxSumR, sumR); RTL[len - 1 - i] = maxSumR; } int result = INT_MIN; for (int i = 0; i < len-1; i++) { result = max(result, LTR[i] + RTL[i + 1]); } return result; }
void chc_drawline(board_t board, int line) { int i, j; move(line, 0); clrtoeol(); if(line == 0) { prints("\033[1;46m 象棋對奕 \033[45m%30s VS %-30s\033[m", cuser.userid, uin->userid); } else if(line >= 3 && line <= 21) { outs(" "); for(i = 0; i < 9; i++) { j = board[RTL(line)][i]; if((line & 1) == 1 && j) { if(chc_selected && chc_select.r == RTL(line) && chc_select.c == i) prints("%s%s\033[m", CHE_O(j) == 0 ? BLACK_REVERSE : RED_REVERSE, chess_str[CHE_O(j)][CHE_P(j)]); else prints("%s%s\033[m", CHE_O(j) == 0 ? BLACK_COLOR : RED_COLOR, chess_str[CHE_O(j)][CHE_P(j)]); } else prints("%c%c", chess_brd[line - 3][i * 4], chess_brd[line - 3][i * 4 + 1]); if(i != 8) prints("%c%c", chess_brd[line - 3][i * 4 + 2], chess_brd[line - 3][i * 4 + 3]); } outs(" "); if(line >= 3 && line < 3 + dim(hint_str)) { outs(hint_str[line - 3]); } else if(line == SIDE_ROW) { prints("\033[1m你是%s%s\033[m", chc_my == 0 ? BLACK_COLOR : RED_COLOR, turn_str[chc_my]); } else if(line == TURN_ROW) { prints("%s%s\033[m", TURN_COLOR, chc_my == chc_turn ? "輪到你下棋了" : "等待對方下棋"); } else if(line == STEP_ROW && !chc_firststep) { showstep(board); } else if(line == TIME_ROW) { prints("剩餘時間 %d:%02d", chc_lefttime / 60, chc_lefttime %60); } else if(line == WARN_ROW) { outs(chc_warnmsg); } else if(line == MYWIN_ROW) { prints("\033[1;33m%12.12s " "\033[1;31m%2d\033[37m勝 " "\033[34m%2d\033[37m敗 " "\033[36m%2d\033[37m和\033[m", cuser.userid, my.chc_win, my.chc_lose , my.chc_tie); } else if(line == HISWIN_ROW) { prints("\033[1;33m%12.12s " "\033[1;31m%2d\033[37m勝 " "\033[34m%2d\033[37m敗 " "\033[36m%2d\033[37m和\033[m", uin->userid, chc_hiswin, chc_hislose , chc_histie); } } else if(line == 2 || line == 22) { outs(" "); if(line == 2) for(i = 1; i <= 9; i++) prints("%s ", num_str[i]); else for(i = 9; i >= 1; i--) prints("%s ", num_str[i]); } }