結果
問題 | No.5 数字のブロック |
ユーザー |
![]() |
提出日時 | 2017-06-22 14:06:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 90 ms / 5,000 ms |
コード長 | 773 bytes |
コンパイル時間 | 622 ms |
コンパイル使用メモリ | 64,560 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-18 11:15:43 |
合計ジャッジ時間 | 2,259 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#include <iostream> using namespace std; void sort(int arr[], int n); void swap(int arr[], int i, int j); int main() { int l, n, k, count, total_width; count = total_width = 0; cin >> l >> n; int block_width[n]; for ( k = 0; k < n; k++ ) { cin >> block_width[k]; } sort(block_width, n); for ( k = 0; k < n; k++ ) { total_width += block_width[k]; if ( total_width > l ) { break; } } cout << k << endl; return 0; } void sort(int arr[], int n) { int k = 1; while ( k < n ) { if ( arr[k-1] <= arr[k] ) { k++; } else { swap(arr, k-1, k); k--; if ( k == 0 ) { k++; } } } } void swap(int arr[], int i, int j) { int t; t = arr[i]; arr[i] = arr[j]; arr[j] = t; }