constructive algorithms greedy *800

Please click on ads to support us..

Python Code:

test = int(input())
while test:
	test -= 1
	n = int(input())
	if(n%3 == 0):
		print("{} {} {}".format(n//3, n//3+1, n//3-1))
	elif n%3==1:
		print("{} {} {}".format(n//3, n//3+2, n//3-1))
	else:
		print("{} {} {}".format(n//3 + 1, n//3+2, n//3-1))

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define lol long long int
#define ff first
#define ss second
#define All(v) v.begin(),v.end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define minus cout<<"-1"<<endl
const int sz = 1e5+5;
const int mod=1e9+7;
const int N=1e6+100;
const int zc=2e5+100;
const int MOD= 998244353;
void fun(){
  ll n;
  cin>>n;
  for(ll i=3;i<n;i++){
    ll ans=(n-i)/2;
    ll res=(n-i-ans);
    if(ans>1 and (res+1<i)){
      ans--;res++;
    }
    if(i>res and res>ans){
      cout<<res<<" "<<i<<" "<<ans<<endl;
      return;
    }
  }
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
   fun();
}
return 0;
}


Comments

Submit
0 Comments
More Questions

260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves
230B - T-primes
630A - Again Twenty Five
1234D - Distinct Characters Queries
1183A - Nearest Interesting Number
1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits
1615A - Closing The Gap
4C - Registration System
1321A - Contest for Robots
1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline
510A - Fox And Snake
1520B - Ordinary Numbers
1624A - Plus One on the Subset
350A - TL
1487A - Arena