AT_abc317_d [ABC317D] President 题解
考虑每一个 的组,拿回 的票需要 个人从 变成 。
直接算出两个人的得分 ,则至少需要 的票。
直接背包就好了。
#pragma GCC optimize("-Ofast,fast-math,-inline")
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 5, MOD = 1e9 + 7; // Remember to change
int n;
struct Node
{
long long x, y, z;
Node(long long _x, long long _y, long long _z): x(_x), y(_y), z(_z){}
Node(){}
}a[N];
namespace FastIo
{
#define QUICKCIN ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
int read()
{
char ch = getchar();
int x = 0, f = 1;
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
while (ch == '-')
{
f = -f;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
template<class T>
void write(T x)
{
if (x < 0)
{
putchar('-');
x = -x;
}
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
template<class T>
void writeln(T x)
{
write(x);
putchar('\n');
}
}
int dp[N];
vector<pair<int, int> > v;
signed main()
{
ios::sync_with_stdio(0), cin.tie(nullptr), cout.tie(nullptr);
cin>>n;
int s1=0,s2=0;
for(int i=1;i<=n;i++)
{
cin>>a[i].x>>a[i].y>>a[i].z;
if(a[i].x<a[i].y)
{
v.emplace_back(make_pair((a[i].y-a[i].x+1)/2, a[i].z));
s2+=a[i].z;
}
else s1+=a[i].z;
}
if(s1>s2) cout<<"0\n";
else
{
int p=(s2-s1+1)/2;
//cout<<p<<"\n";
memset(dp,0x3f,sizeof dp);
dp[0]=0;
for(auto&i:v)
{
//cout<<i.first<<" " << i.second << "\n";
for(int j=100000;j>=i.second;j--)
{
dp[j]=min(dp[j],dp[j-i.second]+i.first);
}
}
int ans=1e18;
for(int i=p;i<=100000;i++) ans=min(ans, dp[i]);
cout<<ans<<"\n";
}
return 0;
}

浙公网安备 33010602011771号