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;
}

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值