/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 14ms 580.0 KiB
#3 Accepted 16ms 536.0 KiB
#4 Accepted 13ms 536.0 KiB
#5 Accepted 14ms 576.0 KiB
#6 Accepted 28ms 452.0 KiB
#7 Accepted 8ms 532.0 KiB
#8 Accepted 4ms 536.0 KiB
#9 Accepted 4ms 532.0 KiB
#10 Accepted 4ms 532.0 KiB
#11 Accepted 5ms 532.0 KiB
#12 Accepted 6ms 532.0 KiB
#13 Accepted 7ms 636.0 KiB
#14 Accepted 7ms 532.0 KiB
#15 Accepted 6ms 532.0 KiB
#16 Accepted 9ms 616.0 KiB
#17 Accepted 9ms 532.0 KiB
#18 Accepted 8ms 532.0 KiB
#19 Accepted 27ms 532.0 KiB
#20 Accepted 24ms 532.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl "\n"
vector<int> takeVectorInput(int n){
    vector<int>v(n);
    for(auto &ele:v)cin>>ele;


//     vector<int>v(n+1);
//    for(int i=1;i<=n;++i) {
//     cin>>v[i];
//    }
    return v;
}
void solve(){
    int n;
    cin>>n;
    auto v=takeVectorInput(n);
    sort(v.begin(),v.end());
    int i=0;
    int j=n-1;
    int ans=0;
    bool completed=true;
    while(i<j){
        // if(v[i]!=-1)break;
        
            if(v[i]==-1&&v[i+1]==-1){
                ans+=v[j];
                i+=2;
                j--;
            }
            else{
                completed=0;
                break;
            }
        
    }
    if(!completed){
    while(j-2>=i){
            ans+=v[j]*v[j-1]*v[j-2];
            j-=3;
        }
    }
    
    cout<<ans<<endl;
}
signed main(){
    fast
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

Information

Submit By
Type
Submission
Problem
P1152 Special Array
Contest
Happy New Year 2025
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-02 14:51:13
Judged At
2025-01-02 14:51:13
Judged By
Score
100
Total Time
28ms
Peak Memory
636.0 KiB