#36792: 內建函式+數學


samlin961112@gmail.com (林哲甫)

學校 : 新北市私立南山高級中學
編號 : 220506
來源 : [219.70.213.92]
最後登入時間 :
2024-04-28 22:43:43
c299. 1. 連號或不連號 -- 106學年度全國資訊學科能力競賽 | From: [219.70.213.92] | 發表日期 : 2023-08-08 22:05

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  while(cin>>n){
    vector<int> a(n);
    for(int i=0;i<n;i++){
     cin>>a[i]; 
    }
    int b=*max_element(a.begin(), a.end());
    int s=*min_element(a.begin(), a.end());
    if(accumulate(a.begin(),a.end(),0)==(b+s)*(b-s+1)/2){
      cout<<s<<' '<<b<<' '<<"yes\n";
    }else{
      cout<<s<<' '<<b<<' '<<"no\n";
    }
  }
}

 
ZeroJudge Forum