Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

dh-winternagi 님의 블로그

(3273) 두 수의 합 본문

백준 (C++)/Solve

(3273) 두 수의 합

dh-winternagi 2026. 4. 19. 19:14

https://www.acmicpc.net/problem/3273

단계별로 풀어보기

30단계(투 포인터) 1번째

 

 

 

참고로 병합 정렬도(정확히는 정렬된 두 배열을 합치는 과정) 투 포인터라고 볼 수 있다.

 

 

 

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  int n, x;
  
  cin >> n;
  
  vector<int> v(n);
  
  for(int i=0;i<n;i++)  cin >> v[i];
  
  sort(v.begin(), v.end());
  
  cin >> x;
  
  int s= 0, e= n-1, ans= 0;
  
  while(s<e){
    ans+= v[s]+v[e]==x;
    
    if(v[s]+v[e]<x)  s++;
    else  e--;
  }
  
  cout << ans;
  
  return 0;
}

'백준 (C++) > Solve' 카테고리의 다른 글

(1806) 부분합  (0) 2026.04.19
(2470) 두 용액  (0) 2026.04.19
(1956) 운동  (0) 2026.04.19
(11404) 플로이드  (0) 2026.04.19
(11657) 타임머신  (0) 2026.04.19