Codeforces Round #568 Div.2
A. Ropewalkers
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h>
using namespace std;
int num[5];
int d;
int main() {
for(int i = 0; i < 3; i ++)
scanf("%d", &num[i]);
scanf("%d", &d);
sort(num, num + 3);
int ans = 0;
if(num[1] - num[0] < d)
ans += d - num[1] + num[0];
if(num[2] - num[1] < d)
ans += d - num[2] + num[1];
printf("%d\n", ans);
return 0;
}
B. Email from Polycarp
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h>
using namespace std;
int T;
string s, t;
bool isSubsequence(string s, string t) {
int ls = s.length(), lt = t.length();
if(!ls) return true;
if(!lt && ls) return false;
int pos = 0, temp = 0;
char c = s[pos];
while(pos <= ls && temp <= lt) {
if(s[pos] == t[temp]) {
c = s[pos];
pos ++;
} else {
if(t[temp] != c) return false;
}
temp ++;
}
return pos == ls + 1;
}
int main() {
scanf("%d", &T);
while(T --) {
cin >> s >> t;
if(isSubsequence(s, t)) printf("YES\n");
else printf("NO\n");
}
return 0;
}
C1. Exam in BerSU (easy version)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int N, M; int a[maxn]; long long num[110]; int main() { scanf("%d%d", &N, &M); memset(num, 0, sizeof(num)); for(int i = 0; i < N; i ++) { scanf("%d", &a[i]); long long ans = 0, maxx = 0; long long sum = M - a[i]; for(int j = 1; j <= 100; j ++) { long long temp = min(sum / j, num[j]); maxx += temp; sum -= temp * j; } num[a[i]] ++; printf("%lld%s", i - maxx, i != N - 1 ? " " : "\n"); } return 0; }
C2. Exam in BerSU (hard version)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int N, M; int a[maxn]; long long num[110]; int main() { scanf("%d%d", &N, &M); memset(num, 0, sizeof(num)); for(int i = 0; i < N; i ++) { scanf("%d", &a[i]); long long ans = 0, maxx = 0; long long sum = M - a[i]; for(int j = 1; j <= 100; j ++) { long long temp = min(sum / j, num[j]); maxx += temp; sum -= temp * j; } num[a[i]] ++; printf("%lld%s", i - maxx, i != N - 1 ? " " : "\n"); } return 0; }