当前位置:网站首页>6133. Maximum number of packets
6133. Maximum number of packets
2022-08-01 23:09:00 【先生高】
6133. Maximum number of groups
You are given an array grades of positive integers representing the grades of some students in the college.You intend to divide all students into ordered non-empty groups where the order between groups satisfies all of the following conditions:
The total grade of students in group i is less than the total grade of students in group (i + 1), true for all groups (except the last group).The total number of students in the ith group is less than the total number of students in the (i + 1)th group, true for all groups (except the last).Returns the maximum number of groups that can be formed.
Example 1:
Input: grades = [10,6,12,7,3,5]
Output: 3
Explanation: Here is one possible way to form 3 groups:
- Students in group 1 have grades = [12] , total grade: 12 , number of students: 1
- Students in group 2 have grades = [6,7] , total grade: 6 + 7 = 13 , number of students: 2
- Students in group 3 have grades = [10,3,5] , total grade: 10 + 3 + 5 = 18 , number of students: 3
It can be shown that no more than 3 groups can be formed.
Example 2:
Input: grades = [8,8]
Output: 1
Explanation: Only 1 group can be formed, because if two groups are to be formed, the number of students in each group will be equal.
This question seems difficult, but it is actually confusing. The code to solve the problem is as follows:
int maximumGroups(int* grades, int gradesSize){for(int i=1;i<1000;i++){int a=(i+1)*i/2;if(a>gradesSize){return i-1;}}return 0;}边栏推荐
猜你喜欢

美赞臣EDI 940仓库装运订单详解

C#大型互联网平台管理框架源码:基于ASP.NET MVC+EF6+Bootstrap开发,支持多数据库
Background project Express-Mysql-Vue3-TS-Pinia page layout-sidebar menu

npm包【详解】(内含npm包的开发、发布、安装、更新、搜索、卸载、查看、版本号更新规则、package.json详解等)

测试岗月薪5-9k,如何实现涨薪到25k?

03、GO语言变量定义、函数

drf生成序列化类代码

域名重定向工具 —— SwitchHosts 实用教程

Wechat Gymnasium Reservation Mini Program Graduation Design Finished Work Mini Program Graduation Design Finished Product (2) Mini Program Function

cmd指令
随机推荐
Jmeter是什么
Calculate the angle of a line defined by two points
From 0 to 1: Design and R&D Notes of Graphic Voting Mini Program
解决端口占用
Deep Learning Course2 Week 2 Optimization Algorithms Exercises
下载安装 vscode(含汉化、插件的推荐和安装)
【参营经历贴】2022网安夏令营
vscode hide menu bar
从0到100:招生报名小程序开发笔记
三、mysql 存储引擎-建库建表操作
CF1705D Mark and Lightbulbs
测试岗月薪5-9k,如何实现涨薪到25k?
联邦学习的框架搭建
文件查询匹配神器 【glob.js】 实用教程
【数据分析03】
10年稳定性保障经验总结,故障复盘要回答哪三大关键问题?|TakinTalks大咖分享
Check if point is inside rectangle
分享10套开源免费的高品质源码,免费源码下载平台
数据分析04
Nacos配置中心之加载配置