intfindTheLongestBalancedSubstring(string s) { int maxlen = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '1') continue; int j; for (j = i; j < s.size(); j++) { if (s[j] == '1') break; }
int ilen = j - i; int k; for (k = j; k < s.size(); k++) { if (s[k] == '0') break; } int jlen = k - j; int len; cout << ilen << ' ' << jlen << endl; if (ilen > jlen) len = jlen * 2; else len = ilen * 2; if (len > maxlen) maxlen = len; } return maxlen; }
intmiceAndCheese(vector<int> &reward1, vector<int> &reward2, int k) { int n = reward1.size(); // 一开始假设都是第二只老鼠吃掉的 longlong ans = 0; for (int x : reward2) ans += x; // 计算每个奶酪的得分变化量 vector<int> vec; for (int i = 0; i < n; i++) vec.push_back(reward1[i] - reward2[i]); sort(vec.begin(), vec.end()); // 选出前 K 大的得分变化量 for (int i = 1; i <= k; i++) ans += vec[n - i]; return ans; }