leetcode 2021.4.5 1
作者:
cloudann
,
2021-04-05 21:47:17
,
所有人可见
,
阅读 374
class Solution {
private:
long long mod;
int len;
int num[int(1e5)];
public:
int combin(int n,int m){
long long sum = ((n*(n-1))%mod)/2;
return sum%mod;
}
int purchasePlans(vector<int>& nums, int target) {
int count=0,mid = target>>1;
stack<int> s;
for(int i=0;i<nums.size();i++){
if(nums[i]<=mid){
count++;
num[nums[i]]++;
}else if(nums[i]<target){
s.push(target-nums[i]);
}
}
for(int i = 1;i<=mid+1;i++)
num[i] +=num[i-1];
long long sum = count>2?combin(count,2):(count==2?1:0);
while(!s.empty()){
sum+=num[s.top()];
s.pop();
sum%=mod;
}
return sum%mod;
}
Solution(){
mod = 1e9 + 7;
len = 1;
}
};