Codeforces Round #598 (Div. 3)
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 int main() { 5 int q; scanf("%d",&q); 6 while (q--) { 7 ll a, b, n, S; 8 scanf("%lld%lld%lld%lld",&a,&b,&n,&S); 9 if (a*n + b < S) puts("NO"); 10 else if (a >= S/n) { 11 if (S - S/n*n > b) puts("NO"); 12 else puts("YES"); 13 } 14 else if (a < S/n) { 15 if (S - a*n > b) puts("NO"); 16 else puts("YES"); 17 } 18 else puts("YES"); 19 } 20 return 0; 21 }
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 105; 4 int a[maxn], n, q; 5 bool vis[maxn]; 6 int find(int num) { 7 for (int i = 1; i <= n; ++i) { 8 if (a[i] == num) return i; 9 } 10 } 11 int main() { 12 scanf("%d",&q); 13 while (q--) { 14 memset(vis,false,sizeof(vis)); 15 scanf("%d",&n); 16 for (int i = 1; i <= n; ++i) { 17 scanf("%d",&a[i]); 18 } 19 for (int i = 1; i <= n; ++i) { 20 int pos = find(i); 21 for (int j = pos; j > i; --j) { 22 if (vis[j-1] == true) break; 23 if (a[j] > a[j-1]) break; 24 vis[j-1] = true; 25 swap(a[j-1],a[j]); 26 } 27 } 28 printf("%d",a[1]); 29 for (int i = 2; i <= n; ++i) { 30 printf(" %d",a[i]); 31 } 32 putchar('\n'); 33 } 34 return 0; 35 }
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 10005; 4 int a[maxn], c[maxn]; 5 int n, m, d; 6 int main() { 7 scanf("%d%d%d",&n,&m,&d); 8 for (int i = 1; i <= m; ++i) { 9 scanf("%d",&c[i]); 10 } 11 int pos = 0; 12 for (int i = 1; i <= m; ++i) { 13 pos = pos+d; 14 /* 15 for (int j = 0; j < c[i]; ++j) { 16 a[pos+j] = i; 17 }*/ 18 pos = pos+c[i]-1; 19 } 20 if (pos + d >= n+1) { 21 puts("YES"); 22 int extra = pos+d-n-1; 23 int pos = 0; 24 for (int i = 1; i <= m; ++i) { 25 if (extra == 0) pos = pos+d; 26 else { 27 if (extra >= d) pos += 1, extra -= d-1; 28 else pos += d-extra, extra = 0; 29 } 30 for (int j = 0; j < c[i]; ++j) { 31 a[pos+j] = i; 32 } 33 pos = pos+c[i]-1; 34 } 35 printf("%d",a[1]); 36 for (int i = 2; i <= n; ++i) { 37 printf(" %d",a[i]); 38 } 39 printf("\n"); 40 } 41 else puts("NO"); 42 return 0; 43 }
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 1e6+5; 5 char s[maxn]; 6 int n, q; 7 ll k; 8 int main() { 9 scanf("%d",&q); 10 while (q--) { 11 scanf("%d%lld",&n,&k); 12 scanf("%s",s+1); 13 14 int pos = 1; 15 for (int i = 1; i <= n && k > 0; ++i) { 16 if (s[i] == '1') continue; 17 else { 18 if (i == pos) { 19 pos++; 20 continue; 21 } 22 if (k >= i-pos) { 23 s[pos] = '0'; s[i] = '1'; 24 k -= i-pos; 25 pos++; 26 } 27 else { 28 s[pos+i-pos-k] = '0'; s[i] = '1'; 29 break; 30 } 31 } 32 //printf("%s\n",s+1); 33 } 34 printf("%s\n",s+1); 35 } 36 return 0; 37 }
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 2e5+5; 4 const int inf = 0x3f3f3f3f; 5 pair<int,int> a[maxn]; 6 int dp[maxn], p[maxn], t[maxn]; 7 int main() { 8 int n; scanf("%d",&n); 9 for (int i = 0; i < n; ++i) { 10 scanf("%d",&a[i].first); 11 a[i].second = i; 12 } 13 sort(a,a+n); 14 fill(dp+1,dp+1+n,inf); 15 fill(p+1,p+1+n,-1); 16 for (int i = 0; i < n; ++i) { 17 for (int j = 3; j <= 5 && i+j <= n; ++j) { 18 int x = a[i+j-1].first - a[i].first; 19 if (dp[i+j] > dp[i]+x) { 20 p[i+j] = i; 21 dp[i+j] = dp[i] + x; 22 } 23 } 24 } 25 int cnt = 1, pos = n; 26 while (pos) { 27 for (int i = pos-1; i >= p[pos]; --i) { 28 t[a[i].second] = cnt; 29 } 30 cnt++; 31 pos = p[pos]; 32 } 33 printf("%d %d\n",dp[n],cnt-1); 34 printf("%d",t[0]); 35 for (int i = 1; i < n; ++i) { 36 printf(" %d",t[i]); 37 } 38 printf("\n"); 39 return 0; 40 }
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 1e6+5; 5 char s[maxn], t[maxn]; 6 int mps[300], mpt[300]; 7 int C[10005]; 8 int lowbit(int x) { 9 return x&(-x); 10 } 11 int sum(int x) { 12 int ret = 0; 13 while (x > 0) { 14 ret += C[x]; x -= lowbit(x); 15 } 16 return ret; 17 } 18 void add(int x, int d) { 19 while (x <= 1000) { 20 C[x] += d; x += lowbit(x); 21 } 22 } 23 int main() { 24 int q; scanf("%d",&q); 25 while (q--) { 26 int n; scanf("%d",&n); 27 scanf("%s%s",s+1,t+1); 28 memset(mps,0,sizeof(mps)); 29 memset(mpt,0,sizeof(mpt)); 30 for (int i = 1; i <= n; ++i) { 31 mps[s[i]]++, mpt[t[i]]++; 32 } 33 bool flag = true; 34 for (char i = 'a'; i <= 'z'; ++i) { 35 if (mps[i] != mpt[i]) flag = false; 36 } 37 if (flag == false) { 38 puts("NO"); 39 continue; 40 } 41 42 memset(C,0,sizeof(C)); 43 ll ans1 = 0, ans2 = 0; 44 for (int i = 1; i <= n; ++i) { 45 ans1 += i-1 - sum(s[i]); 46 add(s[i],1); 47 } 48 memset(C,0,sizeof(C)); 49 for (int i = 1; i <= n; ++i) { 50 ans2 += i-1 - sum(t[i]); 51 add(t[i],1); 52 } 53 //cout << ans1 << " " << ans2 << endl; 54 if (ans1 % 2 == 1 && ans2 % 2 == 0) flag = false; 55 else if (ans1 % 2 == 0 && ans2 % 2 == 1) flag = false; 56 57 for (char i = 'a'; i <= 'z'; ++i) { 58 if (mps[i] > 1) flag = true; 59 } 60 61 if (flag == true) puts("YES"); 62 else puts("NO"); 63 } 64 return 0; 65 }