Dashboard - Codeforces Round 560 (Div. 3) - Codeforces
#include
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;
int n , x , y;
int a[N] , res;
signed main(){
cin >> n >> x >> y;
for(int i = 1 ; i <= n ; i ++) scanf("%01d" , &a[i]);
reverse(a + 1 , a + 1 + n);
y += 1;
for(int i = 1 ; i <= x ; i ++){
if(i == y){
if(a[i] == 0) res += 1;
}else{
if(a[i] == 1) res += 1;
}
}
cout << res;
return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);
#include
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;
int n , a[N];
signed main(){
cin >> n;
for(int i = 1 ; i <= n ; i ++) cin >> a[i];
sort(a + 1 , a + 1 + n);
int now = 0;
for(int i = 1 ; i <= n ; i ++){
if(a[i] >= (now + 1)) now += 1;
}
cout << now;
return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);
#include
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;
/*
ooa
*/
int n , cnt;
string s , ans;
signed main(){
cin >> n >> s;
s = '~' + s;
int now = 0;
for(int i = 1 ; i <= n ; i = now + 1){
ans += s[i];
cnt += 1;
bool tag = 0;
for(int j = i + 1 ; j <= n ; j ++){
if(s[j] != s[i]){
tag = 1;
now = j;
break;
}
}
if(!tag) break;
ans += s[now];
cnt += 1;
}
if(cnt & 1) cnt -= 1;
cout << n - cnt << "\n";
for(int i = 0 ; i < cnt ; i ++) cout << ans[i];
cout << "\n";
return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);
#include
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;
int n , t , a[N];
map<int,int>all;
bool judge(){
map<int,int>mp;
if(n & 1){
for(int i = 1 ; i <= n / 2 + 1 ; i ++){
mp[a[i] * a[n + 1 - i]] += 1;
}
}else{
for(int i = 1 ; i <= n / 2 ; i ++){
mp[a[i] * a[n + 1 - i]] += 1;
}
}
return mp.size() == 1;
}
bool judge1(int x){
for(int i = 2 ; i * i <= x ; i ++){
if(x % i == 0){
if(!all[i]) return 0;
if(!all[x / i]) return 0;
}
}
return 1;
}
signed main(){
IOS
cin >> t;
while(t --){
cin >> n;
all.clear();
for(int i = 1 ; i <= n ; i ++) cin >> a[i] , all[a[i]] += 1;
sort(a + 1 , a + 1 + n);
//第一次判断
if(!judge()){
cout << "-1\n";
}else{
int now = 0;
if(n & 1){
now = a[(n + 1) / 2];
now = now * now;
}else{
now = a[1] * a[n];
}
//第二次判断
if(judge1(now)){
cout << now << "\n";
}else{
cout << "-1\n";
}
}
}
return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);
a n s = ∑ 1 n c n t [ i ] ∗ a [ i ] ∗ b [ i ] ans=\sum_{1}^{n}cnt[i] *a[i]*b[i] ans=1∑ncnt[i]∗a[i]∗b[i]
#include
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 998244353;
typedef pair<int,int>PII;
int a[N] , b[N] , n , cnt[N] , res;
signed main(){
IOS
cin >> n;
for(int i = 1 ; i <= n ; i ++) cin >> a[i];
for(int i = 1 ; i <= n ; i ++) cin >> b[i];
for(int i = 1 ; i <= n ; i ++) cnt[i] = i * (n - i + 1);
for(int i = 1 ; i <= n ; i ++) a[i] = a[i] * cnt[i];
sort(a + 1 , a + 1 + n ,
[&](int a , int b){
return a > b;
}
);
sort(b + 1 , b + 1 + n ,
[&](int a , int b){
return a < b;
}
);
for(int i = 1 ; i <= n ; i ++){
res = (res + a[i] % mod * b[i] % mod) % mod;
}
cout << res ;
return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);
#include
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;
int n , m;
int cnt[N] , sum , cnt_1[N];
map<int , vector<int>>mp;//某个商品的所有打折时间
map<int , vector<int>>ed;//某个时间可以处理的商品
bool judge(int t){
//处理每个商品的最晚打折时间
ed.clear();
for(auto [x , y] : mp){
int res = 0;
for(auto v : y) if(v <= t) res = max(res , v);
ed[res].push_back(x);
}
for(int i = 1 ; i <= n ; i ++) cnt_1[i] = cnt[i];
int need = 0;
for(auto [x , y] : ed){
int now = (x - need);//当前时刻的可用资源
for(auto v : y){
if(cnt_1[v] <= now){
now -= cnt_1[v];
need += cnt_1[v];
cnt_1[v] = 0;
}else{
cnt_1[v] -= now;
need += now;
break;
}
}
}
//未打折使用的资源
for(int i = 1 ; i <= n ; i ++) need += cnt_1[i] * 2;
return need <= t;
}
signed main(){
IOS
cin >> n >> m;
for(int i = 1 ; i <= n ; i ++) cin >> cnt[i];
for(int i = 1 ; i <= m ; i ++){
int x , y;
cin >> x >> y;
mp[y].push_back(x);
}
int l = 0 , r = 4e5;
while(l < r){
int mid = (l + r) >> 1;
if(judge(mid)) r = mid;
else l = mid + 1;
}
cout << l << "\n";
return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);