首页 > 其他分享 >AcWing 第72场周赛

AcWing 第72场周赛

时间:2022-10-15 18:44:09浏览次数:68  
标签:Node 周赛 const int long lhs 72 include AcWing

T1:直接模拟即可。

#include <iostream>
#include <cstring>
#include <algorithm>
#define int long long

using namespace std;

signed main()
{
  int t;
  cin >> t;
  while (t --)
  {
    int a, b;
    cin >> a >> b;
    cout << min({a, b, (a + b) / 3}) << '\n';
  }
  return 0;
}

T2:简单的贪心,按照a-b的顺序排序即可。

#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e6 + 10;
struct Node { int a, b; } z[N];

signed main()
{
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i ++)
    cin >> z[i].a >> z[i].b;
  sort (z + 1, z + n + 1, [&] (const Node &lhs, const Node &rhs)
  {
    return lhs.a - lhs.b > rhs.a - rhs.b;
  });
  int cnt = 0, res = 0, flag = 1;
  for (int i = 1; i <= n; i ++)
    res += z[i].a;
  if (res <= m)
    cout << "0\n";
  else
  {
    for (int i = 1; i <= n; i ++)
    {
      res -= (z[i].a - z[i].b);
      cnt ++;
      if (res <= m)
      {
        flag = 0;
        break;
      }
    }
    if (!flag)
      cout << cnt << '\n';
    else
      cout << "-1\n";
  }
  return 0;
}

T3:AcWing 寄了,明天再干

标签:Node,周赛,const,int,long,lhs,72,include,AcWing
From: https://www.cnblogs.com/BaiduFirstSearch/p/abcdef72.html

相关文章