0% found this document useful (0 votes)
9 views2 pages

Not Too Far Replacement Emzql9

The document contains a C++ program that processes multiple test cases, reading an integer array and performing operations based on certain conditions. It swaps elements of the array based on specific criteria and calculates the sum of the modified array. The program uses modular arithmetic with two different mod values defined, although only one is used in the main logic.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Not Too Far Replacement Emzql9

The document contains a C++ program that processes multiple test cases, reading an integer array and performing operations based on certain conditions. It swaps elements of the array based on specific criteria and calculates the sum of the modified array. The program uses modular arithmetic with two different mod values defined, although only one is used in the main logic.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <bits/stdc++.

h>

using namespace std;

#define int long long int

#define vi vector<int>

#define read(a) for(auto &i: a) cin>>i

#define mod 998244353

#define mod 1000000007

signed main() {

ios_base::sync_with_stdio(false);

cin.tie(NULL);

int t=1;

cin>>t;

while(t--){

int n;

cin>>n;

vi a(n+1,0);

read(a);

int ans=0;

int val=a[n];

while(true){

int maxi=-1;

int pos=-1;

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

if(a[i]<=2*a[n] and a[i]>=maxi and a[n]<a[i]){


maxi=a[i];

pos=i;

if(pos==-1){break;}

swap(a[n],a[pos]);

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

ans=ans+a[i];

cout<<ans<<endl;

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy