SMU Summer 2024 Contest Round 1
1.Sequence Decomposing(利用二分函数并贪心寻找最少的升序数串)
原题链接:http://162.14.124.219/contest/1005/problem/C
查看代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[1000000];
int b[100000];
signed main() {
int n;
cin>>n;
for(int i = 1;i <= n; ++i){
b[i] = -1000000000;
}
for(int i=0;i<n;i++)
{
cin>>a[i];
a[i]*=-1;
}
int ans=1;
b[1]=a[0];
for(int i=1;i<n;i++)
{
int z=upper_bound(b+1,b+ans+1,a[i])-b;
if(z==ans+1)
{
ans++;
b[ans]=a[i];
}
else b[z]=a[i];
}
cout<<ans<<endl;
return 0;
}
2.Integer Cards(将二者分别升序和降序排列,在进行比较替换)
原题链接:http://162.14.124.219/contest/1005/problem/F
查看代码 #include <bits/stdc++.h>
#define int long long
#define PII pair <int,int>
using namespace std;
int a[1000000];
bool cmp(PII x,PII y)
{
return x.second>y.second;
}
signed main() {
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
vector<PII>v;
for(int i=0;i<m;i++)
{
int x,y;
cin>>x>>y;
v.push_back({x,y});
}
sort(v.begin(),v.end(),cmp);
int sum=0;
for(auto i:a)
{
sum+=i;
}
int z=0;
for(int i=0;i<v.size();i++)
{
int f=v[i].first;
int s=v[i].second;
while(a[z]<s&&f!=0&&z<n)
{
if(f>0)f--;
sum-=a[z];
sum+=s;
z++;
}
}
cout<<sum<<endl;
return 0;
}