codeforces #321 DIV2

时间:2022-05-24 11:49:47

A题:

链接:http://codeforces.com/contest/580/problem/A

dp,最长连续不上升子序列

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=;
int a[maxn],dp[maxn];
int main()
{
int n;
while(cin>>n)
{
for(int i=;i<n;i++)
scanf("%d",&a[i]);
memset(dp,,sizeof(dp));
dp[]=;
for(int i=;i<n;i++)
{
if(a[i-]<=a[i])
dp[i]=dp[i-]+;
else
dp[i]=;
}
int mx=;
for(int i=;i<n;i++)
if(dp[i]>mx)
mx=dp[i];
cout<<mx<<endl;
}
return ;
}

B题:

链接:http://codeforces.com/contest/580/problem/B

贪心,先按照m升序排序,然后找出符合条件且最大的

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=;
typedef struct
{
long long m,s;
}point;
point p[maxn];
bool cmp(point a,point b)
{
return a.m<b.m;
}
int main()
{
long long n,d;
while(cin>>n>>d)
{
for(int i=;i<n;i++)
cin>>p[i].m>>p[i].s;
sort(p,p+n,cmp);
long long ans=;
long long cnt=;
int j=;
for(int i=;i<n;i++)
{
cnt+=p[i].s;
while(p[i].m-p[j].m>=d)
{
cnt-=p[j].s;
j++;
}
ans=max(ans,cnt);
}
cout<<ans<<endl;
}
return ;
}

C、D、E赛场上没有搞出来,抽时间来补上