CF1914D Three Activities
题目链接
题面
Winter holidays are coming up. They are going to last forDuring the holidays, Monocarp wants to try all of these activities exactly once with his friends:
- go skiing;
- watch a movie in a cinema;
- play board games.
Monocarp knows that, on the
Monocarp also knows that he can't try more than one activity in a single day.
Thus, he asks you to help him choose three distinct days
Input
The first line contains a single integer
The first line of each testcase contains a single integer
The second line contains
The third line contains
The fourth line contains
The sum of
Output
For each testcase, print a single integer — the maximum total number of friends that can join Monocarp for the activities on three distinct days.
题目大意
给定三个数组
思路
首先想到的当然是枚举
由瞪眼法可知,因为我们只需要找到 当然可以O(n),但我懒.
代码
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define int long long #define endl '\n' using namespace std; void solve() { int n; cin >> n; vector<pair<int, int>> a(n), b(n), c(n); for (int i = 0; i < n; i++) { cin >> a[i].first; // first记录数值 a[i].second = i; // second记录下标 } for (int i = 0; i < n; i++) { cin >> b[i].first; b[i].second = i; } for (int i = 0; i < n; i++) { cin >> c[i].first; c[i].second = i; } sort(all(a)); sort(all(b)); sort(all(c)); //排序,用于取各自最大的三个数 int ans = 0; for (int i = n - 3; i < n; i++) { for (int j = n - 3; j < n; j++) { if (a[i].second == b[j].second) continue; // 下标相同的不符合题意 for (int k = n - 3; k < n; k++) { if (a[i].second == c[k].second || b[j].second == c[k].second) continue; ans = max(ans, a[i].first + b[j].first + c[k].first); } } } cout << ans << endl; } signed main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】