Codeforces Round #956 (Div. 2) and ByteRace 2024 Editorial

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<vi> val(3,vector<int>(n+1));
        vector<vi> pf(3,vector<int>(n+1));
        
        for(int i=0;i<3;i++){
            for(int j=1;j<=n;j++){
                cin>>val[i][j];
                pf[i][j] = pf[i][j-1] + val[i][j];
            }
        }

        bool ok = 0;
        vi perm = {0,1,2};
        int comp = (pf[perm[0]][n]+2)/3;
        for(int i=0;i<6;i++){
            int cur = 1;
            while(cur <= n && pf[perm[0]][cur] < comp) cur++;
            for(int j=cur+1;j<n;j++){
                if(pf[perm[1]][j] - pf[perm[1]][cur] >= comp && pf[perm[2]][n] - pf[perm[2]][j] >= comp){
                    vii ans(3);

                    ans[perm[0]] = {1,cur};
                    ans[perm[1]] = {cur+1,j};
                    ans[perm[2]] = {j+1,n};

                    for(auto x: ans) cout<<x.ff<<' '<<x.ss<<' ';
                    cout<<'\n';
                    ok = 1;
                    break;
                }
            }
            if(ok)break;
            next_permutation(perm.begin(), perm.end());
        }

        if(!ok)cout<<-1<<'\n';
    }
    return 0;
}

相关推荐

  1. Codeforces Round #956 (Div. 2) and ByteRace 2024

    2024-07-11 20:42:02       24 阅读
  2. Codeforces Round #956 (Div. 2) and ByteRace 2024

    2024-07-11 20:42:02       28 阅读
  3. Codeforces Round #956 (Div. 2) and ByteRace 2024 A-C题解

    2024-07-11 20:42:02       24 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 20:42:02       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 20:42:02       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 20:42:02       58 阅读
  4. Python语言-面向对象

    2024-07-11 20:42:02       69 阅读

热门阅读

  1. 【面试题】Golang (第一篇)

    2024-07-11 20:42:02       22 阅读
  2. vue2 使用 Socket.io 实现 WebSocket

    2024-07-11 20:42:02       23 阅读
  3. flink 大数据处理资源分配

    2024-07-11 20:42:02       19 阅读
  4. LiteOS GPIO中断处理

    2024-07-11 20:42:02       20 阅读
  5. python如何与前端交互

    2024-07-11 20:42:02       16 阅读
  6. 模型需要从txt中长文本中精准提炼出来文字

    2024-07-11 20:42:02       22 阅读