A
link
如果选择这一天做题可以让差增加(即我这一天的题数大于他下一天的题数),则选;否则不选。
特殊的,另一个人地\(n+1\)天我们钦定他做了\(0\)道题。
点击查看代码
#include<bits/stdc++.h>using namespace std;int n;
int a[105],b[105];void qwq(){cin >> n;for(int i = 1;i <= n;++ i)cin >> a[i];for(int i = 1;i <= n;++ i)cin >> b[i];b[n+1] = 0;int ans = 0;for(int i = 2;i <= n+1;++ i)if(a[i-1]-b[i] > 0) ans += a[i-1]-b[i];cout << ans << endl;}signed main(){int t;cin >> t;while(t--) qwq();return 0;}
B
link
判断即可。
点击查看代码
#include<bits/stdc++.h>using namespace std;int n,a,b,c;void qwq(){cin >> n >> a >> b >> c;int sum = a+b+c;int w = n/sum;int q = n%sum;w *= 3;if(q != 0&&q <= a) w++;else if(q != 0&&q <= a+b) w += 2;else if(q != 0)w += 3;cout << w << endl;
}signed main(){int t;cin >> t;while(t--) qwq();return 0;}
C
link
如果\(k=n\),那么都可以。
如果\(k<n-1\),那么都不行。
如果\(k=n-1\),那么如果没有的那个他恰好不会,则行,否则不行。
用一个\(bool\)数组\(hav_i\),\(1\)代表\(i\)这个题他会,\(0\)代表\(i\)这个题不会。
点击查看代码
#include<bits/stdc++.h>using namespace std;int n,m,k;
int hav[300005];
int a[300005];
int q[300005];void qwq(){cin >> n >> m >> k;memset(hav,0,sizeof(hav));for(int i = 1;i <= m;++ i)cin >> a[i];for(int i = 1;i <= k;++ i)cin >> q[i],hav[q[i]] = 1;for(int i = 1;i <= m;++ i){if(k == n) cout << 1;else if(k < n-1) cout << 0;else if(hav[a[i]] == 0) cout << 1;else cout << 0;}cout << endl;}signed main(){int t;cin >> t;while(t--) qwq();return 0;}
D
link
二分,枚举选出来的第一个数(靠前那个)是\(a_i\),算出来第二个数(要在\(i+1~n\)中选)要在什么范围内使得满足总和在\(x~y\),设算出来的范围为\(mn~mx\),如果\(mn\)比最大数还大,不行,如果\(mx\)比最小数还小,也不行,剩下的就是可以的情况,二分找出这个范围对应的下标范围即可。
点击查看代码
#include<bits/stdc++.h>#define int long longusing namespace std;int n,x,y;
int a[200005];
int sum;void qwq(){cin >> n >> x >> y;sum = 0;for(int i = 1;i <= n;++ i)cin >> a[i],sum += a[i];sort(a+1,a+1+n);int ans = 0;for(int i = 1;i < n;++ i){int w = sum-a[i];int mn = w-y;int mx = w-x;if(mx < a[i+1]) continue;if(mn > a[n]) continue;int l = i+1,r = n,mid;while(l < r){mid = (l+r)/2;if(a[mid] >= mn) r = mid;else l = mid+1;}w = r;l = i+1,r = n;while(l < r){mid = (l+r+1)/2;if(a[mid] <= mx) l = mid;else r = mid-1;}ans += l-w+1;}cout << ans << endl;}signed main(){int t;cin >> t;while(t--) qwq();return 0;}
E
link
可以理解,价钱一定是\(a\)数组和\(b\)数组\(2n\)个数中的一个。
那么枚举每一个数,二分算出销售量(有多少个\(b_i\)大于价钱)和差评数(销售量减去有多少个\(a_i\)大于价钱(有多少个\(a_i\)大于价钱即好评数)),判断即可。
点击查看代码
#include<bits/stdc++.h>#define int long longusing namespace std;int n,k;
int a[200005],b[200005];
int ans;void solve(int x){int xl = n-(lower_bound(b+1,b+1+n,x)-b-1);int cp = xl-(n-(lower_bound(a+1,a+1+n,x)-a-1));if(cp > k) return;ans = max(ans,xl*x);
}void qwq(){cin >> n >> k;for(int i = 1;i <= n;++ i)cin >> a[i];for(int i = 1;i <= n;++ i)cin >> b[i];sort(a+1,a+1+n);sort(b+1,b+1+n);ans = 0;for(int i = 1;i <= n;++ i){solve(a[i]);solve(b[i]);}cout << ans << endl;}signed main(){int t;cin >> t;while(t--) qwq();return 0;}