Блог пользователя TheInvadr

Автор TheInvadr, история, 8 месяцев назад, По-английски

so for problem 1255B, im trying to connect every fridge to the ones costing the smallest and second smallest then if need be connecting those 2 to each other.its saying that the 503th fridge in the first testcase in the second test can be opened by anyone ? can anyone explain why ? this is my code -

include <bits/stdc++.h>

using namespace std; int main() { int t; cin>>t; while(t--){ // int n,m; int n,m; cin>>n>>m;

pair<int,int> arr[n];
    int a[n];

    for(int i=0;i<n;i++){
        cin>>arr[i].first;
        arr[i].second=i;
    }

    if(n!=m||n==2){
        cout<<-1<<endl;
        continue;
    }

    sort(arr,arr+n);
    vector<pair<int,int>> res;
    int sum = 0;
    int cntf = 0;
    int cnts = 0;

for (int i = 2; i < n; i++) {

sum += arr[i].first + arr[0].first;
res.push_back({arr[i].second+1, arr[0].second + 1});
cntf++;

sum += arr[i].first + arr[1].first;
res.push_back({arr[i].second+1, arr[1].second + 1});
cnts++;

}

if(cntf<2||cnts<2){
        sum+=arr[0].first+arr[1].first;
        res.push_back({arr[0].second+1,arr[1].second+1});
    }

    cout<<sum<<endl;
    for(pair<int,int> i : res)cout<<i.first<<" "<<i.second<<endl;

}

}

  • Проголосовать: нравится
  • -1
  • Проголосовать: не нравится

»
8 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by TheInvadr (previous revision, new revision, compare).

»
8 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by TheInvadr (previous revision, new revision, compare).

»
8 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Your approach has two problems:

First of, directly regarding your question, think about the number of steel chains you are using.

Second:

Spoiler