Educational Codeforces Round 100 (Rated for Div. 2)
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
void io(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
int t,a,b,c;
int main()
{
io();
cin>>t;
while(t--){
cin>>a>>b>>c;
int sum=a+b+c;
int x=(7*sum)/9;
if(9*x==7*sum){
int minn=min(a,min(b,c));
if(x/7>minn) cout<<"NO
";
else cout<<"YES
";
}
else cout<<"NO
";
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
void io() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); }
int t, n;
int a[100], b[100];
int solve(int x,int y)
{
for(int i=1;i<=sqrt(x);++i){
if(x%i==0){
if(abs(y-i)<=y/2) return i;
if(abs(y-x/i)<=y/2) return x/i;
}
}
}
int main()
{
io();
cin >> t;
while (t--) {
cin >> n;
ll sum = 0;
int maxx = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
sum += a[i] * 1ll;
}
ll ts=0;
for(int i=1;i<=n;++i){
if(i%2){
b[i]=1;
}else b[i]=a[i];
ts+=1ll*abs(a[i]-b[i]);
}
if(ts*2ll<=sum) goto ww;
// for(int i=1;i<=n;++i){
// if(a[i]==1||a[i]==2) b[i]=1;
// else b[i]=a[pos];
// }
ts=0;
for(int i=1;i<=n;++i){
if(i%2==0){
b[i]=1;
}else b[i]=a[i];
ts+=1ll*abs(a[i]-b[i]);
}
ww:for (int i = 1; i <= n; ++i) cout << b[i] << " ";
cout << "
";
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
void io() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); }
const ll maxn = 1e5 + 10;
ll T, n;
ll t[maxn], x[maxn];
ll flag[10];
int main()
{
io();
cin >> T;
while (T--) {
cin >> n;
memset(flag, 0, sizeof(flag));
for (ll i = 1; i <= n; ++i) cin >> t[i] >> x[i];
t[n + 1] = 1e18 + 10;
ll x0 = 0, nextt = abs(x[1]) + t[1];
ll np = 0; // nowPlace
ll ep = x[1];
flag[0] = x[1] < x[0] ? 1 : 0; // 1往-走,0往+走
ll ans = 0;
for (ll i = 1; i <= n; ++i) {
if (t[i] >= nextt) {
nextt = t[i] + abs(ep - x[i]);
flag[0] = x[i] < ep ? 1 : 0;
np = ep;
ep = x[i];
}
ll tmp = t[i + 1] - t[i];
ll tep = flag[0] ? np - tmp : np + tmp;// tempEndPlace
if ((x[i] >= np && x[i] <= tep) || (x[i] >= tep && x[i] <= np)) {
if (flag[0]) {
if (x[i] >= ep) ans++;
}
if (!flag[0]) {
if (x[i] <= ep) ans++;
}
}
flag[0] ? np -= tmp : np += tmp;
}
cout << ans << "
";
}
return 0;
}