A. Park Lighting

#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#define form(i,n) for(int i=1;i<=n;i++)
#define forn(i,n) for(int i=0;i<n;i++)
#define mst(a) memset(a,0,sizeof(a))
using namespace std;
typedef pair<int,int> P ;
const int N=1e5;
typedef unsigned long long ull;
typedef long long ll;
const int MAX_N=1e5+20;
struct node{
int x,y;
};
int n,m;
int main(){
ios::sync_with_stdio(0);
int T;
cin>>T;
while (T--){
ll ans=0;
cin>>n>>m;
if(n%2==0&&m%2==0){
cout<<n*m/2<<endl;
}else if(n&1&&m%2==0){
cout<<m/2*n<<endl;
}else if(m&1&&n%2==0){
cout<<n/2*m<<endl;
}else{
cout<<n/2*m+m/2+1<<endl;
}
}
}

B. Maria Breaks the Self-isolation

#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#define form(i,n) for(int i=1;i<=n;i++)
#define forn(i,n) for(int i=0;i<n;i++)
#define mst(a) memset(a,0,sizeof(a))
using namespace std;
typedef pair<int,int> P ;
const int N=1e5;
typedef unsigned long long ull;
typedef long long ll;
const int MAX_N=1e5+20;
struct node{
int x,y;
};
int n,m;
ll a[N];
int main(){
ios::sync_with_stdio(0);
int T;
cin>>T;
while (T--){
cin>>n;
ll in=0;
ll rd=1;
forn(i,n){
cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n;i++){
if(a[i]<=in+rd){
in=in+rd;
rd=1;
}else{
rd++;
}
}
cout<<in+1<<endl;
}
}

C. Celex Update

Time limited

#include <bits/stdc++.h>
#define form(i,n) for(int i=1;i<=n;i++)
#define forn(i,n) for(int i=0;i<n;i++)
#define mst(a) memset(a,0,sizeof(a))
using namespace std;
typedef pair<int,int> P ;
const int N=1e5;
typedef unsigned long long ull;
typedef long long ll;
const int MAX_N=1e5+20;
ll x,y,xx,yy;
int n,m;
ll a[1000][1000];
int main(){
ios::sync_with_stdio(0);
cin>>n;
while (n--){
cin>>x>>y>>xx>>yy;
x=xx-x;
y=yy-y;
cout<<x*y+1<<endl;
}
}

D. The Best Vacation

#include <bits/stdc++.h>#define form(i,n) for(int i=1;i<=n;i++)#define forn(i,n) for(int i=0;i<n;i++)#define mst(a) memset(a,0,sizeof(a))using namespace std;typedef pair<int,int> P ;const int N=1e5;typedef unsigned long long ull;typedef long long ll;const int MAX_N=4e5+20;ll m,n,x,y,xx,yy,ans;ll d[N];int main(){    scanf("%lld%lld", &n, &m);    for (ll i = 1; i <= n; i++){        scanf("%lld", d + i);        d[i + n] = d[i];    }    n = n * 2;    ll l = 1;    ll len = 0, nw = 0;    for (ll i = 1; i <= n; i++){        len += d[i];        nw += d[i] * (d[i] + 1) / 2;        while (len > m){            len -= d[l];            nw -= d[l] * (d[l] + 1) / 2;            l++;        }        if (l > 1) ans = max(ans, nw + (d[l - 1] + d[l - 1] - (m - len) + 1) * (m - len) / 2);        else ans = max(ans, nw);    }    printf("%lld\n", ans);    return 0;}