D.Dyson box
#include <bits/stdc++.h>
using namespace std;
#define ls o<<1
#define rs o<<1|1
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=2e5+10;
const int mod=1e9+7;
const ll inf=0x3f3f3f3f3f3f3f3f;
int n;
int x[maxn],y[maxn];
int res[maxn][2];
set<int> xx,yy;
int cnt[maxn][2];
void solve(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&x[i],&y[i]);
}
for(int i=1;i<=n;i++){
res[i][1]=res[i-1][1];
if(!xx.count(x[i])){
xx.insert(x[i]);
res[i][1]+=2;
}
cnt[x[i]][1]++;
res[i][1]+=2;
if(x[i]-1>=1&&cnt[x[i]][1]<=cnt[x[i]-1][1]) res[i][1]-=2;
if(x[i]+1<=200000&&cnt[x[i]][1]<=cnt[x[i]+1][1]) res[i][1]-=2;
res[i][0]=res[i-1][0];
if(!yy.count(y[i])){
yy.insert(y[i]);
res[i][0]+=2;
}
cnt[y[i]][0]++;
res[i][0]+=2;
// cout<<i<<' '<<res[i][0]<<endl;
if(y[i]-1>=1&&cnt[y[i]][0]<=cnt[y[i]-1][0]) res[i][0]-=2;
if(y[i]+1<=200000&&cnt[y[i]][0]<=cnt[y[i]+1][0]) res[i][0]-=2;
}
for(int i=1;i<=n;i++) printf("%d %d\n",res[i][1],res[i][0]);
}
int main(){
// int T;scanf("%d",&T);while(T--)
solve();
return 0;
}
G.Grade Point Average
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int main()
{
int n,k;
int a[N];
int sum=0;
int b[N],c[N];
cin>>n>>k;
for(int i=n-1;i>=0;i--)
{
scanf("%d",&a[i]);
sum+=a[i];
}
c[0]=sum%n;
printf("%d.",sum/n);
for(int i=0;i<k;i++)
{
b[i]=c[i]*10/n;
c[i+1]=c[i]*10%n;
printf("%d",b[i]);
}
return 0;
}
H.Adventurer's Guild
#include <bits/stdc++.h>
using namespace std;
#define ls o<<1
#define rs o<<1|1
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e3+10;
const int mod=1e9+7;
const ll inf=0x3f3f3f3f3f3f3f3f;
ll dp[2][310][310];
int hh[maxn],ss[maxn];
ll w[maxn];
void solve(){
int n,s,h;
scanf("%d%d%d",&n,&h,&s);
for(int i=1;i<=n;i++){
scanf("%d%d",&hh[i],&ss[i]);
scanf("%lld",&w[i]);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=h;j++){
for(int k=0;k<=s;k++){
dp[1][j][k]=dp[0][j][k];
if(j>hh[i]&&j+k>hh[i]+ss[i]){
int tmp=0;
if(k-ss[i]<0) tmp=k-ss[i];
dp[1][j][k]=max(dp[1][j][k],dp[0][j-hh[i]+tmp][max(k-ss[i],0)]+w[i]);
}
}
}
for(int j=1;j<=h;j++){
for(int k=0;k<=s;k++)
dp[0][j][k]=dp[1][j][k];
}
}
printf("%lld\n",dp[1][h][s]);
}
int main(){
// int T;scanf("%d",&T);while(T--)
solve();
return 0;
}