classSolution{
public:using LL =longlong;intwaysToPartition(vector<int>& nums,int k){
// 前后缀和int n = nums.size();
vector<LL>sum(n+1);
unordered_map<LL,int> oldR, newL;for(int i =1; i <= n; i++){
sum[i]= sum[i-1]+ nums[i-1];if(i >1) oldR[sum[i-1]]++;}
LL tot = sum[n];int res =0;// 不改变if(tot %2==0){
res = oldR[tot/2];}// cout<<res<<endl;// 改变一个位置for(int i =1; i <= n; i++){
int d = k - nums[i-1];if((tot + d)%2==0){
res =max(res, newL[(tot+d)/2]+ oldR[(tot-d)/2]);}
newL[sum[i]]++;
oldR[sum[i]]--;}return res;}};