当前位置:网站首页>Codeforces Global Round 19
Codeforces Global Round 19
2022-07-07 07:46:00 【whitewall_ nine】
B.
This competition is full of violence , I didn't expect the positive solution , For such a complex situation, there must be a conclusion that can make the topic simple . Yes A Speaking of, if it has been ordered , Then it must be no otherwise It indicates that there is a point a[i] > a[j], i < j Or let a[i] < a[j] i > j For the first case, it must be YES, For the second case, we can let j - 1 It is also natural and non reducing . Explain that if there is no order , It must be YES about B Consider greed , Because we need to make the value as big as possible , Let's divide into as many paragraphs as possible , That is to say 1 One number, one segment , except 0 The unexpected number did not contribute , Only 0 Yes, there will be 1 The contribution of . Then consider including 0 All interval numbers of are (i + 1) * (n - i) * (1 + (a[i] == 0));
#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define ll long long
#define pii pair<int, int>
#define mset(s,t) memset(s,t,sizeof(t))
#define mcpy(s,t) memcpy(s,t,sizeof(t))
#define fir first
#define pb push_back
#define sec second
#define sortall(x) sort((x).begin(),(x).end())
inline int read () {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= (ch=='-'),ch= getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f?-x:x;
}
template<typename T> void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) print(x/10);
putchar(x % 10 + '0');
}
#define int long long
const int N = 2e5 + 10;
int n;
int f[N];
int a[N], b[N];
int sum;
void solve() {
cin >> n;
memset(f, 0, sizeof f);
sum = 0;
for (int i = 1; i<= n ;i ++) {
cin >> a[i];
sum += a[i];
}
for (int i = 1; i<= n ;i ++) {
cin >> b[i];
sum += b[i];
}
f[0] = 1;
for (int i = 1; i<= n; i ++) {
int ndp[N] = {0};
for (int j = 0; j <= sum; j ++) {
if (f[j]) {
ndp[j + a[i]] = ndp[j + b[i]] = 1;
}
}
memcpy(f, ndp,sizeof f);
}
int ans = sum * sum;
for (int i = 0; i <= sum; i ++) {
if (f[i])
ans = min (ans, i * i + (sum - i) * (sum - i));
}
for (int i = 1; i <= n; i ++) {
ans += (a[i] * a[i] + b[i] * b[i]) * (n - 2);
}
cout << ans << endl;
}
signed main () {
int t;
cin >> t;
while (t --) solve();
}
01 knapsack problem , Judge which volume is feasible through backpack . Then the formula can be found as shown in the figure One part is unchanged , Then let a part take the minimum . This is a classic technique . Get the global minimum through traversal
边栏推荐
- Deep learning Flower Book + machine learning watermelon book electronic version I found
- 为什么要了解现货黄金走势?
- JS get all date or time stamps between two time stamps
- After 95, the CV engineer posted the payroll and made up this. It's really fragrant
- Solution: could not find kf5 (missing: coreaddons dbusaddons doctools xmlgui)
- 1141_ SiCp learning notes_ Functions abstracted as black boxes
- [unity] several ideas about circular motion of objects
- [Linux] process control and parent-child processes
- [ANSYS] learning experience of APDL finite element analysis
- buuctf misc USB
猜你喜欢
[SUCTF 2019]Game
外包幹了三年,廢了...
解决问题:Unable to connect to Redis
numpy中dot函数使用与解析
07_ Handout on the essence and practical skills of text measurement and geometric transformation
Outsourcing for four years, abandoned
@component(““)
How can a 35 year old programmer build a technological moat?
How to reduce inventory with high concurrency on the Internet
misc ez_usb
随机推荐
Leetcode-206. Reverse Linked List
[unity] several ideas about circular motion of objects
leetcode:105. Constructing binary trees from preorder and inorder traversal sequences
242. Bipartite graph determination
Zhilian + AV, AITO asked M7 to do more than ideal one
Hands on deep learning (IV) -- convolutional neural network CNN
gatk4中的interval是什么??
2022-07-06: will the following go language codes be panic? A: Meeting; B: No. package main import “C“ func main() { var ch chan struct
Tongda injection 0day
聊聊异步编程的 7 种实现方式
Robot technology innovation and practice old version outline
vus. Precautions for SSR requesting data in asyndata function
Why is the row of SQL_ The ranking returned by number is 1
A bit of knowledge - about Apple Certified MFI
Mutual conversion between InputStream, int, shot, long and byte arrays
Outsourcing for four years, abandoned
pytest+allure+jenkins环境--填坑完毕
KBU1510-ASEMI电源专用15A整流桥KBU1510
What is the difference between TCP and UDP?
2、 Concurrent and test notes youth training camp notes