滴滴笔试
#include "iostream"
#include "string"
#include "cstdio"
#include "vector"
#include "cstring"
using namespace std;
long long num[ 100000 ];
int main()
{
int n;
while (cin>>n)
{
memset(num, 0 , sizeof (num));
bool allneg= true ;
for ( int i= 0 ;i<n;++i)
{
cin>>num[i];
if (num[i]>= 0 ) allneg= false ;
}
long long mx=num[ 0 ],sum= 0 ;
if (allneg)
{
for ( int i= 0 ;i<n;++i)
{
if (num[i]>mx)
mx=num[i];
}
}
else
{
for ( int i= 0 ;i<n;++i)
{
if (sum< 0 ) sum= 0 ;
sum=sum+num[i];
if (sum>mx) mx=sum;
}
}
cout<<mx<<endl;
}
return 0 ;
#include "iostream"
#include "string"
#include "cstdio"
#include "cstring"
#include "map"
#include "algorithm"
using namespace std;
struct customer
{
int count;
int money;
};
customer cus[ 50000 ];
int cmp(customer a,customer b)
{
return a.money>b.money;
}
int main()
{
int n,m;
while (cin>>n>>m)
{
memset(cus, 0 , sizeof (cus));
map< int , int > table;
int mx= 0 ;
for ( int i= 0 ;i<n;++i)
{
int a;
cin>>a;
if (mx<a) mx=a;
table[a]++;
}
for ( int i= 0 ;i<m;++i)
cin>>cus[i].count>>cus[i].money;
long long int res= 0 ;
sort(cus,cus+m,cmp);
for ( int i= 0 ;i<m;++i)
{
for ( int k=cus[i].count;k<=mx;++k)
{
if (table[k]> 0 )
{
res+=cus[i].money;
table[k]--;
break ;
}
}
}
cout<<res<<endl;
}
return 0 ;
}