zoukankan      html  css  js  c++  java
  • 1037. Magic Coupon

    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<queue>
    #include<vector>
    #include<cmath>
    #include<iomanip>
    #include<algorithm>
    using namespace std;
    
    bool greaterCmp(int a, int b)
    {
    	return a>b;
    }
    
    int main()
    {
    	int NC,NP,i,j,x;
    	vector<int> v1,v2;
    	cin>>NC;
    	for(i=0; i<NC; i++)
    	{
    		cin>>x;
    		v1.push_back(x);
    	}
    	cin>>NP;
    	for(i=0; i<NP; i++)
    	{
    		cin>>x;
    		v2.push_back(x);
    	}
    	sort(v1.begin(),v1.end(),greaterCmp);
    	sort(v2.begin(),v2.end(),greaterCmp);
    	int sum = 0;
    	i = 0;
    	while(v1[i]>0 && v2[i]>0)
    	{
    		sum += v1[i]*v2[i];
    		i++;
    	}
    	int h1 = v1.size() - 1;
    	int h2 = v2.size() - 1;
    	while(h1>=i && h2>=i && v1[h1]<0 && v2[h2]<0)
    	{
    		sum += v1[h1]*v2[h2];
    		h1--;
    		h2--;
    	}
    	cout<<sum<<endl;
    	return 0;
    }
    

      

    多学习,多总结。
  • 相关阅读:
    LeetCode 260
    LeetCode 258
    LeetCode 237
    LeetCode 226
    LeetCode 203
    LeetCode 202
    codeforces 7D
    codefroces 7C
    codeforces 7B
    codeforces 6E (非原创)
  • 原文地址:https://www.cnblogs.com/yanhaiming/p/2819009.html
Copyright © 2011-2022 走看看